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
VMware: Fixed vmware fact gathering when no physical interfaces have IP Addresses #42600
Conversation
@pdellaert @dericcrago @Im0 @tchernomax @ckotte Could you please review this ? |
lib/ansible/module_utils/vmware.py
Outdated
else: | ||
facts['ipv4'] = ipaddress | ||
if vm.guest.ipAddress: | ||
if '::' in vm.guest.ipAddress: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit of a bad way of checking wether it is IPv6 or IPv4: ::
only occurs if one of the hexadectets is 0000
. You can easily end up with 2001:db8:1:2:3:4:5:6
, which does not contain ::
.
quick fix: check for :
in ipaddress
.
Clean fix: use the ipaddress
python module (python 3.3+ native https://docs.python.org/3/library/ipaddress.html; or https://pypi.org/project/ipaddress/ for 2.6, 2.7 and 3.2, which is a backport (so same functionality).
This is the interesting part:
ipaddress.ip_address(address)
Return an IPv4Address or IPv6Address object depending on the IP address passed as argument. Either IPv4 or IPv6 addresses may be supplied; integers less than 2**32 will be considered to be IPv4 by default. A ValueError is raised if address does not represent a valid IPv4 or IPv6 address.
>>>ipaddress.ip_address('192.168.0.1')
IPv4Address('192.168.0.1')
>>> ipaddress.ip_address('2001:db8::')
IPv6Address('2001:db8::')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll throw the quick fix in for now, I'll leave deciding on adding a python2 dep to @Akasurde .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@bandit145 Thanks for the contribution. @pdellaert thanks for the valuable review. |
…IP Addresses (ansible#42600) * Changed vmware_guest_facts to accuretly reflect ip as displayed in vcenter * fixed ipv6 check
…enter
SUMMARY
Fixes #42597
This changes the way the guest IP address is reported, using guest.ipAddress ensures that if vmware-tools is reporting it then it will get returned (In this specific case no IP for a specific physical interface but a virtual interface exists that vmware-tools detected and reports).
ISSUE TYPE
COMPONENT NAME
vmware_guest_facts
ANSIBLE VERSION
ADDITIONAL INFORMATION