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

vmware_inventory: permit to group by custom field & customize skip_keys #20125

Merged
merged 2 commits into from Jan 12, 2017

Conversation

nerzhul
Copy link
Contributor

@nerzhul nerzhul commented Jan 11, 2017

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

contrib/vmware_inventory.py

ANSIBLE VERSION
2.2.0.0
SUMMARY

This permits to create instances, affect some custom fields like EC2 tags and then retrieve groups from custom fields like EC2 inventory

Example: i have custom field components set to icinga2,grafana on host vmwaretest01 and vmwaretest02
inventory output is:

"vmware_tag_components_icinga2": {
    "hosts": [
      "vmwaretest01",
      "vmwaretest02"
    ]
},
"vmware_tag_components_icinga2": {
    "hosts": [
      "vmwaretest01",
      "vmwaretest02"
    ]
},

Also permit to customize skip_keys value to enhance ourselves the inventory performance. Add resourceconfig to default skip_keys as it doesn't have interesting values for grouping in most cases

@ansibot
Copy link
Contributor

ansibot commented Jan 11, 2017

@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 cloud feature_pull_request needs_triage Needs a first human triage before being processed. vmware VMware community labels Jan 11, 2017
This permits to create instances, affect some custom fields like EC2 tags and then retrieve groups from custom fields like EC2 inventory
@nerzhul nerzhul force-pushed the vmware_inventory_groupby_cf branch 2 times, most recently from 807fef5 to d64c797 Compare January 11, 2017 11:38
@nerzhul nerzhul changed the title vmware_inventory: permit to group by custom field vmware_inventory: permit to group by custom field & customize skip_keys Jan 11, 2017
@gundalow gundalow removed the needs_triage Needs a first human triage before being processed. label Jan 11, 2017
@jctanner
Copy link
Contributor

@dav1x can you also review/test please?

@dav1x
Copy link
Contributor

dav1x commented Jan 11, 2017

@nerzhul

I'm unable to get this working for some reason:

https://www.dropbox.com/s/mjhfx7l95jfw88s/Screenshot%202017-01-11%2011.20.37.png?dl=0

groupby_custom_field = True

# You can customize prefix used by custom field hostgroups generation here.
# vmware_tag_ prefix is the default and consistent with ec2_tag_
custom_field_group_prefix = 'vmware_tag_'   

Am I doing something incorrectly?

I also added a VM tag to make sure that wasn't the problem.

https://www.dropbox.com/s/vjyogztt37jahcp/Screenshot%202017-01-11%2011.25.52.png?dl=0

@nerzhul
Copy link
Contributor Author

nerzhul commented Jan 11, 2017

no just enable it make it works. What is your ESX version ? i suspect you are using tags instead of custom fields

@dav1x
Copy link
Contributor

dav1x commented Jan 11, 2017

vCenter via VCSA 6.5 Build - 4602587

Look at the screenshots in the previous. I'm using both custom attributes and tags. I tried both.

PowerCLI C:\> Get-CustomAttribute -name * -TargetType VirtualMachine

Key   Name                 TargetType
---   ----                 ----------
102   components           VirtualMachine
101   openshift            VirtualMachine

@nerzhul
Copy link
Contributor Author

nerzhul commented Jan 11, 2017

@dav1x you don't have vmware_tag_components_openshift group after a full load with refresh cache ?

@dav1x
Copy link
Contributor

dav1x commented Jan 11, 2017

I do not. I don't see either group.

@nerzhul
Copy link
Contributor Author

nerzhul commented Jan 11, 2017

@dav1x if you do ./vmware_inventory.py --debug --host host do you see "customvalue" field inside object root printed to screen ?

@nerzhul
Copy link
Contributor Author

nerzhul commented Jan 11, 2017

if it's not the case can you send me the full object of one or you host (masking sensible datas) permitting to understand vmware 6.5 API, maybe something has changed (note: just keep 2 level of variables, more is not needed)

@dav1x
Copy link
Contributor

dav1x commented Jan 11, 2017

[root@ose3-ansible-host 20125]# ./vmware_inventory.py --debug --host app-0 | grep openshift
[root@ose3-ansible-host 20125]# 
[root@ose3-ansible-host 20125]# 
[root@ose3-ansible-host 20125]# ./vmware_inventory.py --debug --host app-0 | grep custom
  "customvalue": [], 
    "customvalue": [], 
[root@ose3-ansible-host

No nothing.

https://gist.github.com/dav1x/ed0c3ee4b84b2316162ff2002ed6bd2e

@nerzhul
Copy link
Contributor Author

nerzhul commented Jan 11, 2017

can you set max_object_level=2 instead of max_object_level=1 ? Maybe it's related to recursion, it seem you have fields but they are empty, maybe because of that (and if it's that i will add a notice in the docs)

@dav1x
Copy link
Contributor

dav1x commented Jan 11, 2017

@nerzhul nice! That fixed it!

"'vmware_tag_'openshift_app": {
"hosts": [
"app-2_42255f23-485d-3b8e-5227-c544d8fdd61a",
"app-1_4225c0d8-fbc8-81bd-e452-da57d2a43d81",
"app-0_4225917b-23ae-2285-7516-48a8e33cff6b"
]
},
"'vmware_tag_'components_grafana": {
"hosts": [
"app-2_42255f23-485d-3b8e-5227-c544d8fdd61a"

Verify if customfield is a str before processing custom fields for a host
@nerzhul
Copy link
Contributor Author

nerzhul commented Jan 11, 2017

@dav1x thanks for your time and tests, i added a documentation notice to complete this PR, now it's ready to be shipped :)

@jctanner jctanner merged commit 35f6fb1 into ansible:devel Jan 12, 2017
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_pull_request labels Mar 4, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 cloud feature This issue/PR relates to a feature request. vmware VMware community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants