Skip to content

Change request: Remove unnecessary arrays in inventory host vars #141

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

Closed
DouglasHeriot opened this issue Mar 25, 2020 · 2 comments
Closed
Labels

Comments

@DouglasHeriot
Copy link
Contributor

ISSUE TYPE
  • Feature Idea
SUMMARY

I want to echo the comment by @Yannis100
ansible/ansible#60642 (comment)

I was wondering why values in vars like config_context, sites, manufacturers and so on, were contained in [] brackets; they can have only 1 value and we have to add [0] every time we want to access them. I know that changing this means a lot of people will have to adapt their templates/playbooks but I don't get why it was done like this in the first place.

I guess it just has to do with how group_extractors have 2 separate purposes - not just populating groups, but also filling in host variables. The caller add_host_to_groups assumes extractors always output an array - but wouldn't be hard to change that.

It would also be nice to rename the host variables to be singular instead of plural as necessary - eg. "platform" instead of "platforms". There is no way in the Netbox database for there to be more than one platform of a device.

I plan to implement a fix for this - are we happy for this to be a breaking change, or should it have an option to switch this on/off?

EXPECTED RESULTS
$ ansible-inventory --graph --vars
...
  |--SOME_DEVICE
...
  |  |--{config_context = {}}
  |  |--{device_role = 'ethernet-switch'}
  |  |--{device_type = 'ers-4850gts-pwr'}
  |  |--{manufacturer = 'extreme-networks'}
  |  |--{platform = 'boss'}
  |  |--{rack = 'SOME_RACK'}
  |  |--{site = 'SOME_SITE'}
  |  |--{tags = ['Ansible']}
ACTUAL RESULTS
$ ansible-inventory --graph --vars
...
  |--SOME_DEVICE
...
  |  |--{config_context = [{}]}
  |  |--{device_roles = ['ethernet-switch']}
  |  |--{device_types = ['ers-4850gts-pwr']}
  |  |--{manufacturers = ['extreme-networks']}
  |  |--{platforms = ['boss']}
  |  |--{racks = ['SOME_RACK']}
  |  |--{sites = ['SOME_SITE']}
  |  |--{tags = ['Ansible']}
@DouglasHeriot DouglasHeriot changed the title Change request: Change request: Remove unnecessary arrays in inventory host vars Mar 25, 2020
@FragmentedPacket
Copy link
Contributor

I agree with these changes as well.

I'd say this may have a greater impact so probably have a toggle for it, and then we can deprecate that option eventually.

DouglasHeriot added a commit to hillsong/ansible_modules that referenced this issue Apr 6, 2020
DouglasHeriot added a commit to hillsong/ansible_modules that referenced this issue Apr 7, 2020
DouglasHeriot added a commit to hillsong/ansible_modules that referenced this issue Apr 7, 2020
DouglasHeriot added a commit to hillsong/ansible_modules that referenced this issue Apr 7, 2020
Added separate inventories for plurals on/off
DouglasHeriot added a commit to hillsong/ansible_modules that referenced this issue Apr 7, 2020
DouglasHeriot added a commit to hillsong/ansible_modules that referenced this issue Apr 14, 2020
DouglasHeriot added a commit to hillsong/ansible_modules that referenced this issue Apr 14, 2020
DouglasHeriot added a commit to hillsong/ansible_modules that referenced this issue Apr 14, 2020
Added separate inventories for plurals on/off
DouglasHeriot added a commit to hillsong/ansible_modules that referenced this issue Apr 14, 2020
DouglasHeriot added a commit to hillsong/ansible_modules that referenced this issue Apr 15, 2020
DouglasHeriot added a commit to hillsong/ansible_modules that referenced this issue Apr 15, 2020
DouglasHeriot added a commit to hillsong/ansible_modules that referenced this issue Apr 15, 2020
Added separate inventories for plurals on/off
DouglasHeriot added a commit to hillsong/ansible_modules that referenced this issue Apr 15, 2020
DouglasHeriot added a commit to hillsong/ansible_modules that referenced this issue Apr 21, 2020
DouglasHeriot added a commit to hillsong/ansible_modules that referenced this issue Apr 21, 2020
DouglasHeriot added a commit to hillsong/ansible_modules that referenced this issue Apr 21, 2020
Added separate inventories for plurals on/off
@FragmentedPacket
Copy link
Contributor

Closed via #155

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants