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

Merged
merged 2 commits into from Jan 12, 2017

Projects

None yet

5 participants

@nerzhul
Contributor
nerzhul commented Jan 11, 2017 edited
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

@nerzhul nerzhul vmware_inventory: permit to group by custom field
This permits to create instances, affect some custom fields like EC2 tags and then retrieve groups from custom fields like EC2 inventory
3470a5f
@nerzhul nerzhul changed the title from vmware_inventory: permit to group by custom field to vmware_inventory: permit to group by custom field & customize skip_keys Jan 11, 2017
@gundalow gundalow requested a review from jctanner Jan 11, 2017
@gundalow gundalow removed the needs_triage label Jan 11, 2017
@jctanner
Member

@dav1x can you also review/test please?

@dav1x
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
Contributor
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
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
Contributor
nerzhul commented Jan 11, 2017

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

@dav1x
Contributor
dav1x commented Jan 11, 2017

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

@nerzhul
Contributor
nerzhul commented Jan 11, 2017 edited

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

@nerzhul
Contributor
nerzhul commented Jan 11, 2017 edited

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
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
Contributor
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
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"

@nerzhul @nerzhul nerzhul vmware_inventory: Customize skip_keys & add resourceconfig to skip_keys
Verify if customfield is a str before processing custom fields for a host
ed278fc
@nerzhul
Contributor
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

1 check passed

Shippable Run 9305 status is SUCCESS.
Details
@BondAnthony BondAnthony added a commit to BondAnthony/ansible that referenced this pull request Jan 20, 2017
@nerzhul @BondAnthony nerzhul + BondAnthony vmware_inventory: permit to group by custom field & customize skip_ke…
…ys (#20125)

* vmware_inventory: permit to group by custom field

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

* vmware_inventory: Customize skip_keys & add resourceconfig to skip_keys

Verify if customfield is a str before processing custom fields for a host
9940db6
@tedelhourani tedelhourani pushed a commit to tedelhourani/ansible that referenced this pull request Jan 23, 2017
@nerzhul @hornomos nerzhul + hornomos vmware_inventory: permit to group by custom field & customize skip_ke…
…ys (#20125)

* vmware_inventory: permit to group by custom field

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

* vmware_inventory: Customize skip_keys & add resourceconfig to skip_keys

Verify if customfield is a str before processing custom fields for a host
4668477
@tedelhourani tedelhourani pushed a commit to tedelhourani/ansible that referenced this pull request Jan 23, 2017
@nerzhul @hornomos nerzhul + hornomos vmware_inventory: permit to group by custom field & customize skip_ke…
…ys (#20125)

* vmware_inventory: permit to group by custom field

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

* vmware_inventory: Customize skip_keys & add resourceconfig to skip_keys

Verify if customfield is a str before processing custom fields for a host
49ea62b
@privateip privateip added a commit to privateip/ansible that referenced this pull request Jan 23, 2017
@nerzhul @privateip nerzhul + privateip vmware_inventory: permit to group by custom field & customize skip_ke…
…ys (#20125)

* vmware_inventory: permit to group by custom field

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

* vmware_inventory: Customize skip_keys & add resourceconfig to skip_keys

Verify if customfield is a str before processing custom fields for a host
5493851
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment