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

setup.ps1: added ansible_all_ipv4_addresses ansible_all_ipv6_addresses #560

Conversation

marcohald
Copy link

SUMMARY

This changes collects now all_ipv4_addresses and all_ipv6_addresses as facts like on linux.
The Filtering in the Code is a bit ugly but it returns the ansible_ip_addresses fact the same as here https://github.com/ansible/ansible/blob/74f6e6a134fa4fe57a80c6c0748772ac13182f1b
The Script before this PR did return more IPs than the Test here https://github.com/ansible/ansible/blob/74f6e6a134fa4fe57a80c6c0748772ac13182f1b
Test Output:

10.162.xxx.162
fe80::1176:3b0e:xxxx:8337
192.168.xxx.90
fe80::214d:402a:xxxx:52b3
2a02:8071:xxxx:1720:3c5c:1c67:xxxx:8fcc
2a02:8071:xxxx:1720:4cba:16c4:xxxx:4d7f
172.19.xxx.1
fe80::f2b6:75ca:xxxx:7ed5

Before this PR:

fe80::1176:3b0e:xxxx:8337%33
10.162.xxx.162
fe80::9672:696a:xxxx:9744%18
169.254.xxx.121
fe80::999:4f2d:xxxx:72f5%35
169.254.xxx.95
fe80::36b6:5dce:xxxx:d52d%20
169.254.xxx.20
fe80::78e2:9185:xxxx:827d%17
169.254.xxx.217
2a02:8071:xxxx:1720:4cba:16c4:xxxx:4d7f
2a02:8071:xxxx:1720:3c5c:1c67:xxxx:8fcc
fe80::214d:402a:xxxx:52b3%24
192.168.xxx.90
fe80::152e:5bd:xxxx:e40%38
169.254.xxx.211
fe80::f2b6:75ca:xxxx:7ed5%83
172.19.xxx.1

This PR:

172.19.xxx.1
192.168.xxx.90
10.162.xxx.162
fe80::f2b6:75ca:xxxx:7ed5
fe80::214d:402a:xxxx:52b3
2a02:8071:xxxx:1720:4cba:16c4:xxxx:4d7f
2a02:8071:xxxx:1720:3c5c:1c67:xxxx:8fcc
fe80::1176:3b0e:xxxx:8337

It does also report ipv4 and ipv6 addresses seperate like on Linux

PS C:\Users\adimhald\powershell-ansible> $ansibleFacts

Name                           Value
----                           -----
module_setup                   True
ansible_all_ipv6_addresses     {fe80::f2b6:75ca:xxxx:7ed5, fe80::214d:402a:xxxx:52b3, 2a02:8071:xxxx:1720:4cba:16c4:xxxx:4d7f, 2a02:8071:xxxx:1720:3c5c:1c67:xxxx:8fcc…}
ansible_all_ipv4_addresses     {172.19.xxx.1, 192.168.xxx.90, 10.162.xxx.162}
ansible_ip_addresses           {172.19.xxx.1 192.168.xxx.90 10.162.xxx.162, fe80::f2b6:75ca:xxxx:7ed5 fe80::214d:402a:xxxx:52b3 2a02:8071:xxxx:1720:4cba:16c4:xxxx:4d7f 2a02:8071:xxxx:1720:3c5c:1c67:xxxx:8fcc fe80::1176:3b0e:xxxx:8337}
ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

setup

ADDITIONAL INFORMATION

First Pr opened on the wrong Repo ansible/ansible#81991
The Timing got even better with the CIM call instead of the Net Method. (Timing in ms)

Net CIM
PS5 132 93
PS7 132 85

net-ps5
net-ps5
net-ps7
net-ps7
cim-ps5
cim-ps5
cim-ps7
cim-ps7

@marcohald
Copy link
Author

@jborean93 @nitzmahone sorry for direct pinging.
I just wanted to know if this PR needs anything or if I just have to wait till somebody have time to review it.

Copy link
Collaborator

@jborean93 jborean93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay in reviewing this, I've been working on a few other things which has taken up my time recently. I'm not opposed to adding the extra ipv4 and ipv6 only addresses but I do have some concerns about moving back to CIM. While it may be faster we've had issues with CIM when it comes to non-admin users as well as corruption in the cache causing either a timeout or a slowdown in the task causing issues for users. We would need to continue using the dotnet API or something else other than CIM that gives us the data that is needed.

It would also be great to figure out why GetAllNetworkInterfaces() is returning more interfaces than the CIM method you have in this PR. What are those extra entries, can they be omitted, can we easily omit them?

Finally we would need to have a changelog fragment added to the PR to document these new return values. More details on this can be found at https://docs.ansible.com/ansible/latest/community/development_process.html#creating-changelog-fragments.

$_.Address.ToString() -notin @('::1', '127.0.0.1')
} | ForEach-Object -Process {
$_.Address.ToString()
$NetIPAddress = Get-CimInstance -Namespace ROOT/StandardCimv2 -ClassName MSFT_NetIPAddress
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are purposefully avoiding WMI/CIM in this module where we can as it won't work when a user is running as a non-admin. The data returned by the dotnet methods should contain enough information in the $_.Address object that tells you whether it's an IPv4 vs IPv6 address. As for why it's returning extra entries compared to the CIM method that might be something you need to investigate on your host to figure out what those extra entries are from and whether we should filter them out or not.

$_.Address.ToString()
$NetIPAddress = Get-CimInstance -Namespace ROOT/StandardCimv2 -ClassName MSFT_NetIPAddress

$ips = @()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a minor nit but it might be nicer to use a generic list here instead of += with an array. At the number of ips being added it's mostly inconsequential but I find it always nice to avoid += on arrays regardless.

Copy link

This pull request is stale because it has been open for 4 weeks with no activity. Remove stale label or comment or this will be closed in 2 weeks.

@github-actions github-actions bot added the stale label Dec 14, 2023
@github-actions github-actions bot closed this Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants