Skip to content

Allow IPv6 with NetworkInterfaceIPConfiguration - #582

Merged
xuzhang3 merged 1 commit into
ansible-collections:devfrom
imrejonk:networkinterface-ipconfig-ipv6
Aug 6, 2021
Merged

Allow IPv6 with NetworkInterfaceIPConfiguration#582
xuzhang3 merged 1 commit into
ansible-collections:devfrom
imrejonk:networkinterface-ipconfig-ipv6

Conversation

@imrejonk

Copy link
Copy Markdown
Contributor
SUMMARY

The ip_configurations parameter of the azure_rm_networkinterface module did not allow specifying the IP version, causing the Azure REST API to default to IPv4. Trying to add a public IPv6 address to the network interface would cause this error:

Error creating or updating network interface mynic - Azure Error: IPVersionForPublicIpAndNicIpConfigurationMustMatch
    Message: IP version for publicIPAddress '/subscriptions/[..]/resourceGroups/ansible/providers/Microsoft.Network/publicIPAddresses/mypublicipv6address', version 'IPv6' and network
    interface ipConfiguration '/subscriptions/[..]/resourceGroups/ansible/providers/Microsoft.Network/networkInterfaces/mynic/ipConfigurations/myipv6config', version 'IPv4' must match.

The Azure Python SDK however does allow for a parameter called private_ip_address_version. This commit implements that parameter for the azure_rm_networkinterface module.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

azure_rm_networkinterface

ADDITIONAL INFORMATION

You can now do this:

- name: Create network interfaces
  azure_rm_networkinterface:
    name: 'mynic'
    resource_group: 'myrg'
    location: 'westeurope'
    virtual_network: 'myvirtnet'
    subnet_name: 'mysubnet'
    ip_configurations:
      - name: 'myipv4config'
        primary: True
        public_ip_address_name: 'mypublicipv4address'
        private_ip_address_version: 'IPv4'
      - name: 'myipv6config'
        primary: False
        public_ip_address_name: 'mypublicipv6address'
        private_ip_address_version: 'IPv6'

And I can remove an ugly workaround involving an Ansible command task that just called azure-cli to add IPv6 configurations to network interfaces 😊

@Fred-sun

Copy link
Copy Markdown
Collaborator

@imrejonk Thanks for your contribution. Can you add test cases for the newly added feature? Thank you very much!

@imrejonk

Copy link
Copy Markdown
Contributor Author

No problem, I'll add some test cases next week. I just got service principal authentication working for ansible-test and am now doing some trial runs with the existing integration tests.

@imrejonk imrejonk changed the title Allow IPv6 with NetworkInterfaceIPConfiguration Draft: Allow IPv6 with NetworkInterfaceIPConfiguration Jul 15, 2021
@imrejonk
imrejonk force-pushed the networkinterface-ipconfig-ipv6 branch from b2de5fb to e22c298 Compare July 22, 2021 13:50
@imrejonk

Copy link
Copy Markdown
Contributor Author

@Fred-sun I've modified the azure_rm_networkinterface integration tests to account for this change and rebased my branch. I also fixed an idempotency issue related to the primary parameter, which was being set from null to False on the second run when the parameter was omitted.

Some things to note:

  • I've set the public IP address SKU to 'standard', and the allocation method to 'static'. This is due to limitations in Azure's IPv6 support.
  • The total number of public IP addresses being created now comes to four: two for the load balancer (IPv4 and IPv6), and two for the network interface.
  • Mixing 'basic' with 'standard' SKUs in a load balancer or NIC configuration is not allowed, so I had to change how IPv4 public addresses were created in the tests.
  • I noticed that network security groups and the virtual network were not being removed after running the tests, so I added tasks for cleaning them up.

Let me know if this is sufficient, and if not, what types of additional tests you would like to see.

@imrejonk imrejonk changed the title Draft: Allow IPv6 with NetworkInterfaceIPConfiguration Allow IPv6 with NetworkInterfaceIPConfiguration Jul 22, 2021
Comment thread tests/integration/targets/azure_rm_networkinterface/tasks/main.yml Outdated
Comment thread tests/integration/targets/azure_rm_networkinterface/tasks/main.yml Outdated
The ip_configurations parameter of the azure_rm_networkinterface module
did not allow specifying the IP version, causing the Azure REST API to
default to IPv4. Trying to add a public IPv6 address to the network
interface would cause this error:

```
Error creating or updating network interface mynic - Azure Error: IPVersionForPublicIpAndNicIpConfigurationMustMatch
    Message: IP version for publicIPAddress '/subscriptions/[..]/resourceGroups/ansible/providers/Microsoft.Network/publicIPAddresses/mypublicipv6address', version 'IPv6' and network
    interface ipConfiguration '/subscriptions/[..]/resourceGroups/ansible/providers/Microsoft.Network/networkInterfaces/mynic/ipConfigurations/myipv6config', version 'IPv4' must match.
```

The Azure Python SDK however does allow for a parameter called
`private_ip_address_version` [0]. This commit implements that parameter
for the azure_rm_networkinterface module.

[1] https://docs.microsoft.com/en-us/python/api/azure-mgmt-network/azure.mgmt.network.v2020_06_01.models.networkinterfaceipconfiguration?view=azure-python
@imrejonk
imrejonk force-pushed the networkinterface-ipconfig-ipv6 branch from e22c298 to af28e0a Compare July 26, 2021 11:44
@imrejonk

Copy link
Copy Markdown
Contributor Author

@Fred-sun here you go, style issues fixed.

@Fred-sun Fred-sun added medium-priority Medium priority new-feature This issue/PR is related to a new feature introduced. ready-for-review The PR is ready to be reviewed and merged. labels Aug 2, 2021
@Fred-sun

Fred-sun commented Aug 2, 2021

Copy link
Copy Markdown
Collaborator

@Fred-sun here you go, style issues fixed.

@imrejonk Merger will be promoted in the near future. Thank you very much!

@xuzhang3

xuzhang3 commented Aug 6, 2021

Copy link
Copy Markdown
Contributor

LGTM

@xuzhang3
xuzhang3 merged commit fba2684 into ansible-collections:dev Aug 6, 2021
Fred-sun pushed a commit to Fred-sun/ansible_collections_azure that referenced this pull request Aug 11, 2021
)

The ip_configurations parameter of the azure_rm_networkinterface module
did not allow specifying the IP version, causing the Azure REST API to
default to IPv4. Trying to add a public IPv6 address to the network
interface would cause this error:

```
Error creating or updating network interface mynic - Azure Error: IPVersionForPublicIpAndNicIpConfigurationMustMatch
    Message: IP version for publicIPAddress '/subscriptions/[..]/resourceGroups/ansible/providers/Microsoft.Network/publicIPAddresses/mypublicipv6address', version 'IPv6' and network
    interface ipConfiguration '/subscriptions/[..]/resourceGroups/ansible/providers/Microsoft.Network/networkInterfaces/mynic/ipConfigurations/myipv6config', version 'IPv4' must match.
```

The Azure Python SDK however does allow for a parameter called
`private_ip_address_version` [0]. This commit implements that parameter
for the azure_rm_networkinterface module.

[1] https://docs.microsoft.com/en-us/python/api/azure-mgmt-network/azure.mgmt.network.v2020_06_01.models.networkinterfaceipconfiguration?view=azure-python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

medium-priority Medium priority new-feature This issue/PR is related to a new feature introduced. ready-for-review The PR is ready to be reviewed and merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants