Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azure_rm_networkinterface does not notice changed IPs #1404

Open
Nothing4You opened this issue Jan 12, 2024 · 0 comments · May be fixed by #1405
Open

azure_rm_networkinterface does not notice changed IPs #1404

Nothing4You opened this issue Jan 12, 2024 · 0 comments · May be fixed by #1405
Labels
bug Something isn't working enhancement New feature or request has_pr PR fixes have been made medium_priority Medium priority

Comments

@Nothing4You
Copy link

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:

# check the ip_configuration is changed
# construct two set with the same structure and then compare
# the list should contains:
# name, private_ip_address, public_ip_address_name, private_ip_allocation_method, subnet_name
ip_configuration_result = self.construct_ip_configuration_set(results['ip_configurations'])
ip_configuration_request = self.construct_ip_configuration_set(self.ip_configurations)
ip_configuration_result_name = [item['name'] for item in ip_configuration_result]
for item_request in ip_configuration_request:
if item_request['name'] not in ip_configuration_result_name:
changed = True
break
else:
for item_result in ip_configuration_result:
if len(ip_configuration_request) == 1 and len(ip_configuration_result) == 1:
item_request['primary'] = True
if item_request['name'] == item_result['name'] and item_request != item_result:
changed = True
break

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

def construct_ip_configuration_set(self, raw):
configurations = [dict(
private_ip_allocation_method=to_native(item.get('private_ip_allocation_method')),
public_ip_address_name=(to_native(item.get('public_ip_address').get('name'))
if item.get('public_ip_address') else to_native(item.get('public_ip_address_name'))),
primary=item.get('primary'),
load_balancer_backend_address_pools=(set([to_native(self.backend_addr_pool_id(id))
for id in item.get('load_balancer_backend_address_pools')])
if item.get('load_balancer_backend_address_pools') else None),
application_gateway_backend_address_pools=(set([to_native(self.gateway_backend_addr_pool_id(id))
for id in item.get('application_gateway_backend_address_pools')])
if item.get('application_gateway_backend_address_pools') else None),
application_security_groups=(set([to_native(asg_id) for asg_id in item.get('application_security_groups')])
if item.get('application_security_groups') else None),
name=to_native(item.get('name'))
) for item in raw]
return configurations

Nothing4You added a commit to Nothing4You/azure that referenced this issue Jan 12, 2024
@Fred-sun Fred-sun added enhancement New feature or request medium_priority Medium priority bug Something isn't working has_pr PR fixes have been made labels Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request has_pr PR fixes have been made medium_priority Medium priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants