f5-ansible icon indicating copy to clipboard operation
f5-ansible copied to clipboard

bigip_static_route not idempotent when create a role

Open muhammad-rafi opened this issue 3 years ago • 6 comments

COMPONENT NAME

bigip_static_route

Environment

ANSIBLE VERSION
2.9.16
BIGIP VERSION
BIG-IP v15.1.2.1 (Build 0.0.10)
CONFIGURATION
OS / ENVIRONMENT

CentOS7

SUMMARY

Seems like bigip_static_route is not idempotent when create I role, otherwise runs OK, please see my steps below; let me know if I am doing something wrong

STEPS TO REPRODUCE
- name: F5 BIGIP PLAYBOOK 
  hosts: bigip
  gather_facts: false  
  connection: local
  collections: 
    - f5networks.f5_modules
    
  vars:
    cli:
      server: "{{ inventory_hostname }}"
      user: "{{ ansible_user }}"
      password: "{{ ansible_pass }}"
      server_port: "{{ port }}"
      validate_certs: no

  roles:
    - bigip-static-route

bigip-static-route main.yml file

- name: Create static route with gateway address
  bigip_static_route:
    name: "{{ item.name }}"
    description: "{{ item.description }}"
    destination: "{{ item.destination }}"
    netmask: "{{ item.netmask }}"
    gateway_address: "{{ item.gateway_address }}"
    partition: "{{ item.partition }}"
    # mtu: "{{ item.mtu }}"
    route_domain: "{{ item.route_domain }}"
    state: "{{ item.state }}"
    provider: "{{ cli }}"
  delegate_to: localhost
  with_items: "{{ static_route }}"

Variables for this role

static_route:
  - name: default_route 
    description: default_route
    destination: 0.0.0.0
    netmask: 0.0.0.0
    gateway_address: 192.168.10.254
    partition: TENANT_1
    route_domain: 1
    state: present 
EXPECTED RESULTS

Module should be idempotent

ACTUAL RESULTS

It shows the changed even though there is no change

[ansible@vCentOS f5-bigip-project]$ ansible-playbook playbooks/bigip-rolebook.yml -vvv
ansible-playbook 2.9.16
  config file = /opt/ansible/f5-bigip-project/ansible.cfg
  configured module search path = ['/opt/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/ansible/.local/lib/python3.6/site-packages/ansible
  executable location = /opt/ansible/.local/bin/ansible-playbook
  python version = 3.6.8 (default, Aug 10 2019, 06:54:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
Using /opt/ansible/f5-bigip-project/ansible.cfg as config file
host_list declined parsing /opt/ansible/f5-bigip-project/inventory.yml as it did not pass its verify_file() method
script declined parsing /opt/ansible/f5-bigip-project/inventory.yml as it did not pass its verify_file() method
Parsed /opt/ansible/f5-bigip-project/inventory.yml inventory source with yaml plugin
Skipping callback 'actionable', as we already have a stdout callback.
Skipping callback 'counter_enabled', as we already have a stdout callback.
Skipping callback 'debug', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'full_skip', as we already have a stdout callback.
Skipping callback 'json', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'null', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
Skipping callback 'selective', as we already have a stdout callback.
Skipping callback 'skippy', as we already have a stdout callback.
Skipping callback 'stderr', as we already have a stdout callback.
Skipping callback 'unixy', as we already have a stdout callback.
Skipping callback 'yaml', as we already have a stdout callback.

PLAYBOOK: bigip-rolebook.yml ***************************************************************************************
1 plays in playbooks/bigip-rolebook.yml

PLAY [F5 BIGIP ROOLBOOK] *******************************************************************************************
META: ran handlers

TASK [bigip-static-route : Task to create static route with gateway address] ***************************************
task path: /opt/ansible/f5-bigip-project/roles/bigip-static-route/tasks/main.yml:3
Friday 09 July 2021  17:07:37 +0100 (0:00:00.260)       0:00:00.260 ***********
included: /opt/ansible/f5-bigip-project/roles/bigip-static-route/tasks/static-route.yml for eve-bigip01.devnetbro.com, eve-bigip02.devnetbro.com

TASK [bigip-static-route : Create static route with gateway address] ***********************************************
task path: /opt/ansible/f5-bigip-project/roles/bigip-static-route/tasks/static-route.yml:4
Friday 09 July 2021  17:07:38 +0100 (0:00:00.248)       0:00:00.509 ***********
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: ansible
<localhost> EXEC /bin/sh -c 'echo ~ansible && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /opt/ansible/.ansible/tmp `"&& mkdir "` echo /opt/ansible/.ansible/tmp/ansible-tmp-1625846858.1829479-31016-184983224882612 `" && echo ansible-tmp-1625846858.1829479-31016-184983224882612="` echo /opt/ansible/.ansible/tmp/ansible-tmp-1625846858.1829479-31016-184983224882612 `" ) && sleep 0'
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: ansible
<localhost> EXEC /bin/sh -c 'echo ~ansible && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /opt/ansible/.ansible/tmp `"&& mkdir "` echo /opt/ansible/.ansible/tmp/ansible-tmp-1625846858.2130032-31017-30542780572999 `" && echo ansible-tmp-1625846858.2130032-31017-30542780572999="` echo /opt/ansible/.ansible/tmp/ansible-tmp-1625846858.2130032-31017-30542780572999 `" ) && sleep 0'
Using module file /opt/ansible/.local/lib/python3.6/site-packages/ansible/modules/network/f5/bigip_static_route.py
Using module file /opt/ansible/.local/lib/python3.6/site-packages/ansible/modules/network/f5/bigip_static_route.py
<localhost> PUT /opt/ansible/.ansible/tmp/ansible-local-31005pnlvb19e/tmpat3xoc7v TO /opt/ansible/.ansible/tmp/ansible-tmp-1625846858.1829479-31016-184983224882612/AnsiballZ_bigip_static_route.py
<localhost> PUT /opt/ansible/.ansible/tmp/ansible-local-31005pnlvb19e/tmpbk239vcf TO /opt/ansible/.ansible/tmp/ansible-tmp-1625846858.2130032-31017-30542780572999/AnsiballZ_bigip_static_route.py
<localhost> EXEC /bin/sh -c 'chmod u+x /opt/ansible/.ansible/tmp/ansible-tmp-1625846858.1829479-31016-184983224882612/ /opt/ansible/.ansible/tmp/ansible-tmp-1625846858.1829479-31016-184983224882612/AnsiballZ_bigip_static_route.py && sleep 0'
<localhost> EXEC /bin/sh -c 'chmod u+x /opt/ansible/.ansible/tmp/ansible-tmp-1625846858.2130032-31017-30542780572999/ /opt/ansible/.ansible/tmp/ansible-tmp-1625846858.2130032-31017-30542780572999/AnsiballZ_bigip_static_route.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python3.6 /opt/ansible/.ansible/tmp/ansible-tmp-1625846858.2130032-31017-30542780572999/AnsiballZ_bigip_static_route.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python3.6 /opt/ansible/.ansible/tmp/ansible-tmp-1625846858.1829479-31016-184983224882612/AnsiballZ_bigip_static_route.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /opt/ansible/.ansible/tmp/ansible-tmp-1625846858.2130032-31017-30542780572999/ > /dev/null 2>&1 && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /opt/ansible/.ansible/tmp/ansible-tmp-1625846858.1829479-31016-184983224882612/ > /dev/null 2>&1 && sleep 0'
changed: [eve-bigip02.devnetbro.com] => (item={'name': 'default_route', 'description': 'default_route', 'destination': '0.0.0.0', 'netmask': '0.0.0.0', 'gateway_address': '192.168.10.254', 'partition': 'TENANT_1', 'route_domain': 1, 'state': 'present'}) => {
    "ansible_loop_var": "item",
    "changed": true,
    "gateway_address": "192.168.10.254",
    "invocation": {
        "module_args": {
            "description": "default_route",
            "destination": "0.0.0.0",
            "gateway_address": "192.168.10.254",
            "mtu": null,
            "name": "default_route",
            "netmask": "0.0.0.0",
            "partition": "TENANT_1",
            "pool": null,
            "provider": {
                "auth_provider": null,
                "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "server": "eve-bigip02.devnetbro.com",
                "server_port": 443,
                "ssh_keyfile": null,
                "timeout": null,
                "transport": "rest",
                "user": "root",
                "validate_certs": false
            },
            "reject": null,
            "route_domain": 1,
            "state": "present",
            "vlan": null
        }
    },
    "item": {
        "description": "default_route",
        "destination": "0.0.0.0",
        "gateway_address": "192.168.10.254",
        "name": "default_route",
        "netmask": "0.0.0.0",
        "partition": "TENANT_1",
        "route_domain": 1,
        "state": "present"
    }
}
changed: [eve-bigip01.devnetbro.com] => (item={'name': 'default_route', 'description': 'default_route', 'destination': '0.0.0.0', 'netmask': '0.0.0.0', 'gateway_address': '192.168.10.254', 'partition': 'TENANT_1', 'route_domain': 1, 'state': 'present'}) => {
    "ansible_loop_var": "item",
    "changed": true,
    "gateway_address": "192.168.10.254",
    "invocation": {
        "module_args": {
            "description": "default_route",
            "destination": "0.0.0.0",
            "gateway_address": "192.168.10.254",
            "mtu": null,
            "name": "default_route",
            "netmask": "0.0.0.0",
            "partition": "TENANT_1",
            "pool": null,
            "provider": {
                "auth_provider": null,
                "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "server": "eve-bigip01.devnetbro.com",
                "server_port": 443,
                "ssh_keyfile": null,
                "timeout": null,
                "transport": "rest",
                "user": "root",
                "validate_certs": false
            },
            "reject": null,
            "route_domain": 1,
            "state": "present",
            "vlan": null
        }
    },
    "item": {
        "description": "default_route",
        "destination": "0.0.0.0",
        "gateway_address": "192.168.10.254",
        "name": "default_route",
        "netmask": "0.0.0.0",
        "partition": "TENANT_1",
        "route_domain": 1,
        "state": "present"
    }
}
META: ran handlers
META: ran handlers

PLAY RECAP *********************************************************************************************************
eve-bigip01.devnetbro.com  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  
eve-bigip02.devnetbro.com  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  

Friday 09 July 2021  17:07:40 +0100 (0:00:02.250)       0:00:02.759 ***********
===============================================================================
bigip-static-route : Create static route with gateway address ----------------------------------------------- 2.25s
/opt/ansible/f5-bigip-project/roles/bigip-static-route/tasks/static-route.yml:4 -----------------------------------
bigip-static-route : Task to create static route with gateway address --------------------------------------- 0.25s
/opt/ansible/f5-bigip-project/roles/bigip-static-route/tasks/main.yml:3 -------------------------------------------

muhammad-rafi avatar Jul 09 '21 16:07 muhammad-rafi

@muhammad-rafi - Unable to reproduce this issue with devel build. Can you recheck the same. for multiple times I just see ok=1 and changed=0

trinaths avatar Jul 14 '21 19:07 trinaths

Hi @trinaths , I have tried with the devel and results are same, infact I try to compare this devel with the collections I download from galaxy, both modules are identical, you think I may be doing something wrong ? let me know please if you need more details.

muhammad-rafi avatar Jul 18 '21 22:07 muhammad-rafi

@muhammad-rafi I tested using the below playbook.

  tasks:
    - name: Create static route with gateway address
      bigip_static_route:
        name: default_route
        description: default_route
        destination: 0.0.0.0
        netmask: 0.0.0.0
        gateway_address: 192.168.10.250
        partition: Common
        route_domain: 0
        state: present
        provider: "{{ provider }}"
      delegate_to: localhost

Can you try the above playbook. did not usewith_items ?

trinaths avatar Jul 19 '21 17:07 trinaths

@trinaths, In your example above, you hard coded the parameters which is idempotent and even if you pass the variable via with_items will be OK too but as soon as you create a role like in my original question, it looses the idempotency, let me know if this make sense ?

muhammad-rafi avatar Jul 21 '21 12:07 muhammad-rafi

Created INFRAANO-495 for internal tracking

trinaths avatar Sep 13 '21 15:09 trinaths

Hi @muhammad-rafi , I don't think it is an issue if the output you mentioned is coming only when you run the playbook for the first time. Could you please tell if you see the same output even after running the playbook multiple times without making any changes to the playbook and the static routes?

urohit011 avatar Oct 25 '21 09:10 urohit011

Hi, we are closing this request now. Please re-open if required or send an email to [email protected]. Thanks!

KrithikaChidambaram avatar Feb 17 '23 09:02 KrithikaChidambaram