azure icon indicating copy to clipboard operation
azure copied to clipboard

azure_rm_networkinterface does not notice changed IPs

Open Nothing4You opened this issue 2 years ago • 0 comments

SUMMARY

Updating the static IP of an ip_configuration will not update it during task execution.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

azure_rm_networkinterface

ANSIBLE VERSION
ansible [core 2.16.2]
  config file = /Users/myuser/vgn/ansible/ansible.cfg
  configured module search path = ['/Users/myuser/vgn/ansible/library']
  ansible python module location = /Users/myuser/.asdf/installs/python/3.11.6/lib/python3.11/site-packages/ansible
  ansible collection location = /Users/myuser/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/myuser/.asdf/installs/python/3.11.6/bin/ansible
  python version = 3.11.6 (main, Nov 14 2023, 01:31:00) [Clang 15.0.0 (clang-1500.0.40.1)] (/Users/myuser/.asdf/installs/python/3.11.6/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
# /Users/myuser/.ansible/collections/ansible_collections
Collection         Version
------------------ -------
azure.azcollection 2.1.1
CONFIGURATION
N/A
OS / ENVIRONMENT

N/A

STEPS TO REPRODUCE
- hosts: localhost
  connection: local

  gather_facts: false

  tasks:
    - name: Create a network interface
      azure_rm_networkinterface:
        subscription_id: my-subscription-id
        resource_group: my-resource-group
        name: testnic001
        virtual_network: /subscriptions/my-subscription-id/resourceGroups/some-resource-group/providers/Microsoft.Network/virtualNetworks/vnet-name
        subnet_name: subnetname
        create_with_security_group: false
        ip_configurations:
          - name: ipconfig1
            private_ip_allocation_method: Static
            private_ip_address: 172.16.0.5

    - name: Change network interface private ip
      azure_rm_networkinterface:
        subscription_id: my-subscription-id
        resource_group: my-resource-group
        name: testnic001
        virtual_network: /subscriptions/my-subscription-id/resourceGroups/some-resource-group/providers/Microsoft.Network/virtualNetworks/vnet-name
        subnet_name: subnetname
        create_with_security_group: false
        ip_configurations:
          - name: ipconfig1
            private_ip_allocation_method: Static
            private_ip_address: 172.16.0.6
EXPECTED RESULTS

The interface gets provisioned with static IP 172.16.0.5 in the first task, then it gets updated to 172.16.0.6 in the second task. Re-running the playbook should change it back to 5 and 6 again.

PLAY [localhost] ****************************************************************************************************

TASK [Create a network interface] ***********************************************************************************
changed: [localhost]

TASK [Change network interface private ip] **************************************************************************
changed: [localhost]

PLAY RECAP **********************************************************************************************************
localhost                  : ok=2    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
ACTUAL RESULTS

After the interface is initially created, the IP will not be updated. This can be done via Azure portal without any issues. Running the playbook a second time will report zero changes.

PLAY [localhost] ****************************************************************************************************

TASK [Create a network interface] ***********************************************************************************
changed: [localhost]

TASK [Change network interface private ip] **************************************************************************
ok: [localhost]

PLAY RECAP **********************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
Additional information

In the code, the logic is described to be supposed to compare the dicts of existing config with desired config, explicitly mentioning private_ip_address:

https://github.com/ansible-collections/azure/blob/e4b6d2bd953d10cac742a0d96b199078bde7e7a2/plugins/modules/azure_rm_networkinterface.py#L781-L798

The problem appears to be that construct_ip_configuration_set does not include private_ip_address:

https://github.com/ansible-collections/azure/blob/e4b6d2bd953d10cac742a0d96b199078bde7e7a2/plugins/modules/azure_rm_networkinterface.py#L952-L968

Nothing4You avatar Jan 12 '24 17:01 Nothing4You