tested on Ubuntu 20.04 ..

I am able to see all vms 

eg 


            "xx": {
                "Application": "xx",
                "Environment": "xx",
                "LOB": "xx",
                "Location": "xx",
                "NB_LAST_BACKUP": "xx",
                "OS": "Ubuntu18.04",
                "ansible_host": "xx",
                "categories": [
                    "Backup Retention Policy",
                    "OS"
                ],
                "config.guestId": "ubuntu64Guest",
                "config.name": "xx",
                "guest.ipAddress": "xx",
                "runtime.connectionState": "connected",
                "summary.runtime.powerState": "poweredOn",
                "tag_category.Backup Retention Policy": [
                    "Backup-Bronze"
                ],
                "tag_category.OS": [
                    "Ubuntu18.04"
                ],
                "tags": [
                    "Backup-Bronze",
                    "Ubuntu18.04"
                ]
            }
        }
    },





As soon as i added 


filters:
- OS is defined and OS == 'Ubuntu18.04'

I get below 

{
    "_meta": {
        "hostvars": {}
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    }
}




Any suggestions Please ?

On Monday, February 8, 2021 at 4:46:24 PM UTC-8 [email protected] wrote:

> Now the error :
>
>
>  ansible-inventory --list -i vmware.yml
> [WARNING]:  * Failed to parse /etc/ansible/playbooks/vmware.yml with 
> ansible_collections.community.vmware.plugins.inventory.vmware_vm_inventory 
> plugin: Unable to find 'vSphere
> Automation SDK' Python library which is required. Please refer this URL 
> for installation steps - 
> https://code.vmware.com/web/sdk/7.0/vsphere-automation-python
> [WARNING]: Unable to parse /etc/ansible/playbooks/vmware.yml as an 
> inventory source
> [WARNING]: No inventory was parsed, only implicit localhost is available
> {
>     "_meta": {
>         "hostvars": {}
>     },
>     "all": {
>         "children": [
>             "ungrouped"
>         ]
>     }
> }
>
>
>
>
>
>
>
>
>
> #######################################
>
>
> tried below 2 
>
> scl enable rh-python36 bash
>  ansible-inventory --list -i vmware.yml
> [WARNING]:  * Failed to parse /etc/ansible/playbooks/vmware.yml with 
> ansible_collections.community.vmware.plugins.inventory.vmware_vm_inventory 
> plugin: Unable to find 'vSphere
> Automation SDK' Python library which is required. Please refer this URL 
> for installation steps - 
> https://code.vmware.com/web/sdk/7.0/vsphere-automation-python
> [WARNING]: Unable to parse /etc/ansible/playbooks/vmware.yml as an 
> inventory source
> [WARNING]: No inventory was parsed, only implicit localhost is available
> {
>     "_meta": {
>         "hostvars": {}
>     },
>     "all": {
>         "children": [
>             "ungrouped"
>         ]
>     }
> }
>
>
>
> #######################################
>
>
>
>  python --version
> Python 3.6.12
>
>  ansible --version
> ansible 2.9.14
>   config file = /etc/ansible/ansible.cfg
>   configured module search path = [u'/root/.ansible/plugins/modules', 
> u'/usr/share/ansible/plugins/modules']
>   ansible python module location = /usr/lib/python2.7/site-packages/ansible
>   executable location = /usr/bin/ansible
>   python version = 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 
> 20150623 (Red Hat 4.8.5-44)]
>
>
> OS :-
> Distributor ID: CentOS
> Description:    CentOS Linux release 7.9.2009 (Core)
> Release:        7.9.2009
> Codename:       Core
>
>
> #######################################
>
>
>
> Now i will try what you gave 
>
> #######################################
>
> - 'customValue' # <----------------------------------  This way you can 
> specify the customValues
> filters:
> - OS is defined and OS == 'Linux' #   <---------------------------------- 
> This way you can filter customValue 
>
> ###############################
> ########
>
>
>
> Install was done & was ok when i upgrade to python 3x :
>
>
> https://github.com/vmware/vsphere-automation-sdk-python#installing-required-python-packages
>
> pip install --upgrade pip setuptools
> pip install --upgrade git+
> https://github.com/vmware/vsphere-automation-sdk-python.git
>
>
> Per notes in 
> https://github.com/vmware/vsphere-automation-sdk-python#installing-required-python-packages
>
>
>
> Please suggest ( google did not give any clue for fix ) 
>
>
>
> On Monday, February 8, 2021 at 4:36:05 PM UTC-8 [email protected] wrote:
>
>>
>> Link :
>>
>>
>> https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_vm_inventory_inventory.html
>>
>> last 2 lines 
>>
>> filters: - "tag_category.OS is defined and 'Linux' in tag_category.OS"
>>
>> How to i add "AND" or "OR" here ?
>>
>> OS = CentOS7 
>> And 
>> LOB = Infra 
>>
>>
>>
>>
>> On Monday, February 8, 2021 at 4:33:47 PM UTC-8 [email protected] wrote:
>>
>>> Abhijit actually i came across that one & tried below .. "per the 
>>> documents" .. which were confusing BTW .. soon i will give link
>>>
>>> filters:
>>> - "tag_category.OS is defined and 'Ubuntu16.04' in tag_category.OS"
>>>
>>> I had difficult  time to get this tested .. as for "tags" you see some 
>>> extra stuff install & that install though looks straighforward but took me 
>>> for spin .. so i am more into fixing the python issues ... May be you can 
>>> help.. soon i will give all i tried & error i got .. 
>>>
>>>
>>>
>>> On Sunday, February 7, 2021 at 8:17:41 PM UTC-8 Abhijeet Kasurde wrote:
>>>
>>>> Hi,
>>>>
>>>> You can use custom attributes assigned to vms using inventory. Let us 
>>>> assume that a VM has attributes as "OS" = "Linux" and "Backup" = "Monday" 
>>>> then
>>>> your inventory configuration looks like - 
>>>>
>>>> plugin: community.vmware.vmware_vm_inventory
>>>> strict: False
>>>> hostname: 10.8.36.25
>>>> username: [email protected]
>>>> password: 2gJ.aGq8AU*tPAaii_
>>>> validate_certs: False
>>>> hostnames:
>>>> - 'config.name'
>>>> properties:
>>>> - 'config.name'
>>>> - 'config.guestId'
>>>> - 'guest.ipAddress'
>>>> - 'summary.runtime.powerState'
>>>> - 'customValue' # <----------------------------------  This way you can 
>>>> specify the customValues
>>>> filters:
>>>> - OS is defined and OS == 'Linux' #   
>>>> <---------------------------------- This way you can filter customValue
>>>>
>>>>
>>>> You will get results like 
>>>>
>>>> # ansible-inventory -i filters_custom_attributes_vmware.yml --list
>>>> {
>>>>     "_meta": {
>>>>         "hostvars": {
>>>>             "centos_7": {
>>>>                 "Backup": "Monday",
>>>>                 "OS": "Linux",
>>>>                 "config.guestId": "centos7_64Guest",
>>>>                 "config.name": "centos_7",
>>>>                 "runtime.connectionState": "connected",
>>>>                 "summary.runtime.powerState": "poweredOff"
>>>>             }
>>>>         }
>>>>     },
>>>>     "all": {
>>>>         "children": [
>>>>             "centos7_64Guest",
>>>>             "poweredOff",
>>>>             "ungrouped"
>>>>         ]
>>>>     },
>>>>     "centos7_64Guest": {
>>>>         "hosts": [
>>>>             "centos_7"
>>>>         ]
>>>>     },
>>>>     "poweredOff": {
>>>>         "hosts": [
>>>>             "centos_7"
>>>>         ]
>>>>     }
>>>> }
>>>>
>>>>
>>>> Let me know if you need any additional information.
>>>>
>>>> On Sun, Feb 7, 2021 at 3:43 PM [email protected] <[email protected]> 
>>>> wrote:
>>>>
>>>>> I checked that one, seems close, does that mean this feature is now in 
>>>>> ? the docs does not talk about that - 
>>>>> https://docs.ansible.com/ansible/devel/scenario_guides/vmware_scenarios/vmware_inventory_filters.html
>>>>>  
>>>>>
>>>>> Thanks 
>>>>>
>>>>> On Tuesday, September 8, 2020 at 12:17:32 AM UTC-7 Abhijeet Kasurde 
>>>>> wrote:
>>>>>
>>>>>> Hi,
>>>>>> I raised a PR to address - how to use filters in vmware_vm_inventory 
>>>>>> - https://github.com/ansible/ansible/pull/71670 
>>>>>> Please provide the feedback. 
>>>>>>
>>>>>> On Sat, Sep 5, 2020 at 9:10 AM [email protected] <[email protected]> 
>>>>>> wrote:
>>>>>>
>>>>>>> The page 
>>>>>>>
>>>>>>>
>>>>>>> https://docs.ansible.com/ansible/devel/scenario_guides/vmware_scenarios/vmware_inventory_hostnames.html
>>>>>>>
>>>>>>>
>>>>>>> Does not talk or give examples of filter .. 
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Friday, September 4, 2020 at 8:25:48 PM UTC-7 [email protected] 
>>>>>>> wrote:
>>>>>>>
>>>>>>>> i tested & found below works though 
>>>>>>>>
>>>>>>>> filters: - runtime.powerState == "poweredOff" 
>>>>>>>>
>>>>>>>>
>>>>>>>> i am using 
>>>>>>>> ansible 2.9.10
>>>>>>>>
>>>>>>>>  
>>>>>>>>
>>>>>>>> On Friday, September 4, 2020 at 8:16:22 PM UTC-7 [email protected] 
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> tried but no luck 
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> plugin: community.vmware.vmware_vm_inventory
>>>>>>>>> strict: False
>>>>>>>>> hostname: xxx
>>>>>>>>> username: [email protected]
>>>>>>>>> password: xxx
>>>>>>>>> validate_certs: False
>>>>>>>>> #properties:
>>>>>>>>> #- runtime.powerState
>>>>>>>>> #- config.name
>>>>>>>>> properties:
>>>>>>>>> - 'name'
>>>>>>>>> - 'config.uuid'
>>>>>>>>> - 'config.name'
>>>>>>>>> - 'guest.toolsStatus'
>>>>>>>>> - 'guest.toolsRunningStatus'
>>>>>>>>> - 'guest.ipAddress'
>>>>>>>>> - 'configIssue'
>>>>>>>>> - 'config.bootOptions'
>>>>>>>>> - 'config.annotation'
>>>>>>>>> - 'config.alternateGuestName'
>>>>>>>>> compose:
>>>>>>>>>   ansible_host: 'guest.ipAddress'
>>>>>>>>> keyed_groups:
>>>>>>>>>     - key: 'tags'
>>>>>>>>>       separator: ''
>>>>>>>>> filters:
>>>>>>>>> - guest.GuestFullName == "CentOS 7 (64-bit)"
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Friday, September 4, 2020 at 12:21:46 PM UTC-7 
>>>>>>>>> [email protected] wrote:
>>>>>>>>>
>>>>>>>>>> @abijit reported  community.vmware.vmware_vm_inventory  but i did 
>>>>>>>>>> not find doc about it ie what all capabilities its filter has 
>>>>>>>>>>
>>>>>>>>>>  
>>>>>>>>>>
>>>>>>>>>> On Friday, September 4, 2020 at 12:12:04 PM UTC-7 
>>>>>>>>>> [email protected] wrote:
>>>>>>>>>>
>>>>>>>>>>> Hi
>>>>>>>>>>>
>>>>>>>>>>> Needs any suggestion in my case as below 
>>>>>>>>>>>
>>>>>>>>>>> We have vCenter where many linux bases vm which are use by other 
>>>>>>>>>>> lob, there is no proper naming standard , no ip based filter 
>>>>>>>>>>> possible , no 
>>>>>>>>>>> folders arranged properly 
>>>>>>>>>>>
>>>>>>>>>>> With all this, one thing which is in my control is add  "custom 
>>>>>>>>>>> attributes"  
>>>>>>>>>>>
>>>>>>>>>>> Is there any way we can filter using "custom attributes' 
>>>>>>>>>>>
>>>>>>>>>>> Thanks 
>>>>>>>>>>>
>>>>>>>>>> -- 
>>>>>>> You received this message because you are subscribed to the Google 
>>>>>>> Groups "Ansible Project" group.
>>>>>>> To unsubscribe from this group and stop receiving emails from it, 
>>>>>>> send an email to [email protected].
>>>>>>> To view this discussion on the web visit 
>>>>>>> https://groups.google.com/d/msgid/ansible-project/e9399bfb-3e24-4ab6-9fa5-46016a86a925n%40googlegroups.com
>>>>>>>  
>>>>>>> <https://groups.google.com/d/msgid/ansible-project/e9399bfb-3e24-4ab6-9fa5-46016a86a925n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>> .
>>>>>>>
>>>>>>
>>>>>>
>>>>>> -- 
>>>>>> Thanks,
>>>>>> Abhijeet Kasurde
>>>>>>
>>>>> -- 
>>>>> You received this message because you are subscribed to the Google 
>>>>> Groups "Ansible Project" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>>> an email to [email protected].
>>>>>
>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/ansible-project/1268d7a3-fd28-4b89-9a91-2815e97a9ad7n%40googlegroups.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/ansible-project/1268d7a3-fd28-4b89-9a91-2815e97a9ad7n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>
>>>>
>>>> -- 
>>>> Thanks,
>>>> Abhijeet Kasurde
>>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/db1ee75a-1851-4e70-8988-d1160cac29dbn%40googlegroups.com.

Reply via email to