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

Assigning group variables in inventory module #189

Open
mkrawczyszyn opened this issue Jul 22, 2022 · 1 comment
Open

Assigning group variables in inventory module #189

mkrawczyszyn opened this issue Jul 22, 2022 · 1 comment
Labels
type/enhancement New feature or request

Comments

@mkrawczyszyn
Copy link

SUMMARY

It would be very handy to have possibility to add not only host variables but also group variables. Is this feature planned?

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

Now inventory module.

ADDITIONAL INFORMATION

N/A

@epicanthal
Copy link

I think because this inventory plugin is based upon ansible.builtin.constructed which doesn't provide your feature...maybe it wouldn't be added? Maybe you can request your feature idea in the core Ansible project? Then all other projects' inventory plugins based on constructed would be able to take advantage?

I think the idea is that you use group_vars for supplying group variables. e.g. if you use the sample webservers dynamic group from the constructed documentation:

plugin: ansible.builtin.constructed
strict: False
compose:
    var_sum: var1 + var2

    # this variable will only be set if I have a persistent fact cache enabled (and have non expired facts)
    # `strict: False` will skip this instead of producing an error if it is missing facts.
    server_type: "ansible_hostname | regex_replace ('(.{6})(.{2}).*', '\\2')"
groups:
    # simple name matching
    webservers: inventory_hostname.startswith('web')

you can then have the vars file in group_vars/webservers.yml:

var1: value1
var2: value2
etc.

@tima tima added the type/enhancement New feature or request label Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants