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

Add support for extra vars in ansible.builtin.generator plugin #83271

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

Roysav
Copy link

@Roysav Roysav commented May 19, 2024

Reference

This pull request addresses issue #83270

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 Pull Request

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

@ansibot ansibot added feature This issue/PR relates to a feature request. needs_triage Needs a first human triage before being processed. labels May 20, 2024
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label May 21, 2024
template_inputs = product(*config['layers'].values())
for item in template_inputs:
template_vars = dict()
template_vars.update(extra_vars)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks backwards compatibility, add a new option (see constructed, use_extra_vars, use_vars_plugins) . After that you should add a changelog and tests. https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html#generating-changelogs

@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label May 21, 2024
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label May 28, 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. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants