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

Allow usage of extra vars in ansible.builtin.generator inventory plugin, enabling the dynamic generation of inventory host names at runtime. #83270

Open
1 task done
Roysav opened this issue May 19, 2024 · 1 comment
Labels
feature This issue/PR relates to a feature request. has_pr This issue has an associated PR.

Comments

@Roysav
Copy link

Roysav commented May 19, 2024

Summary

Use Cases

VM Creation

  • Scenario: Using Ansible to both create VMs and configure them. Consistency in hostname generation is critical to ensure seamless transitions between creation and configuration phases.
  • Solution: By enabling the ansible.builtin.generator plugin to use extra vars, it will be possible to dynamically generate consistent hostnames based on variables provided at runtime. This ensures consistency across already existing virtual machines (that may be sourced from dynamic inventory plugin) and newly created virtual machines. This consistency is important for the use of group_vars and host_vars in the configuration phase.

Issue Type

Feature Idea

Component Name

plugins/inventory/generator.py

Additional Information

In inventory.yaml file:

plugin: ansible.builtin.generator
hosts:
    # The `region` variable is provided at runtime
    name: "{{ region }}{{ machine_type }}"
layers:
    machine_type:
        - web
        - db

Running:

ansible-inventory -i inventory.yaml -e region=region10 --list

Should output:

@all:
  |--@ungrouped:
  |  |--region10web
  |  |--region10db

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibot
Copy link
Contributor

ansibot commented May 19, 2024

Files identified in the description:

None

If these files are incorrect, please update the component name section of the description or use the component bot command.

@ansibot ansibot added feature This issue/PR relates to a feature request. needs_triage Needs a first human triage before being processed. labels May 19, 2024
@ansibot ansibot added the has_pr This issue has an associated PR. label May 20, 2024
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue/PR relates to a feature request. has_pr This issue has an associated PR.
Projects
None yet
Development

No branches or pull requests

3 participants