Open fvahid opened 3 years ago
Files identified in the description: None
If these files are inaccurate, please update the component name
section of the description or use the !component
bot command.
@fvahid: Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information.
Here are the items we could not find in your description:
Please set the description of this issue with this template: https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE/bug_report.md
!component =plugins/inventory/vmware_vm_inventory.py
Files identified in the description:
plugins/inventory/vmware_vm_inventory.py
](https://github.com/['ansible-collections/amazon.aws', 'ansible-collections/community.aws', 'ansible-collections/community.vmware']/blob/main/plugins/inventory/vmware_vm_inventory.py)If these files are inaccurate, please update the component name
section of the description or use the !component
bot command.
cc @Tomorrow9 @goneri @pgbidkar @warthog9 click here for bot help
@fvahid Thanks for reporting this issue.
What is net.guest
? This is not a valid value. You may want to refer https://docs.ansible.com/ansible/latest/scenario_guides/vmware_scenarios/vmware_inventory_vm_attributes.html#ipaddress-str-optional for a valid value.
needs_info
Thanks @Akasurde I use this document https://docs.ansible.com/ansible/latest/scenario_guides/vmware_scenarios/vmware_inventory_vm_attributes.html#ipaddress-str-optional but ipAddress (str, optional) return only first ip in vmware , I need to get second IP for example, when my vmware quest have got multiple IP address problem occurred
if you see this picture I need to get 100.0.0.71 and put to ansible_host vars
@fvahid you can do like this
compose:
ansible_host: 'guest.net[1].ipAddress[0]'
for me -
{
"_meta": {
"hostvars": {
"centos_7": {
"ansible_host": "192.168.101.10",
"config": {
"guestId": "centos7_64Guest",
"name": "centos_7"
},
But this is NOT RECOMMENDED since not every VM has a valid IP address at net[1]
and ipAddress[0]
.
needs_info
maybe some vm have 'guest.net[0].ipAddress[1]' or 'guest.net[2].ipAddress[1]' valid IP address how can I filter correct ip, I teste json_parser I did not work something like this ansible_host: "guest.net | json_parser(json_query.....)"
every time that I restart guest vm IP order in guest.net changed and absolutely 'guest.net[0].ipAddress[1] value change to another IP
any update @Akasurde
I have the same issue, using ansible 2.9.23. Our datacenter has servers with multiple NICs on different networks, and only one of those NICs can connect with our Ansible nodes, and it's usually not the first one. So I want to be able to select the IP address from the list of dicts in guest.net.
I have tried this:
compose: ansible_host: "{{ guest.net|select('ipAddress', 'contains', '10.177.') }}"
And I have tried this:
compose: ansible_host: "{% for item in guest.net %} {% if '10.177.' in item.ipAddress[0] %} {{ item.ipAddress[0] }} {% endif %} {% endfor %}"
And I have tried many variations on these with additional jinja filters, specifying the object with [0] or [1], but nothing returns an IP address for ansible_host. The only expression that sometimes works is:
"{{ guest.net[2].ipAddress[0] }}"
However this only selects the third IP address, which isn't always the correct one. I need to be able to choose the subnet. This is a big issue for us and prevents us from being able to use this plugin.
My current workaround is to set the vcenter vm name to the DNS entry of the interface I want to talk to via ansible (and use config.name). OK for me but not optimal for the admittedly few vm's that are sitting on several distributed switches. It would be way easier to filter using something like the '| select' that @cscal above tried - or better yet a parameter specifying a substring pattern to match.
This looks like a dup with https://github.com/ansible-collections/community.vmware/issues/1008.
@goneri @Akasurde since #1008 has been resolved by #1310, I think this issue here can be closed as well.
My VM have multiple IP address after inventory sync on AWX , ansible_host value is not match to my need, is any solution exist to fix the problem and filter one desire ip?
I used compose var like this ansible_host: net.guest | json_parser (...) but did not works
Thanks