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

[Discussion] Cleaner way to pass var values #250

Closed
alxiong opened this issue May 28, 2020 · 1 comment
Closed

[Discussion] Cleaner way to pass var values #250

alxiong opened this issue May 28, 2020 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@alxiong
Copy link
Contributor

alxiong commented May 28, 2020

Currently, many variables in the playbook are supplied via ansible-playbook xxx.yaml --extra-vars "@some_file.yaml"

Here's a cleaner (arguably better) way:

  vars_files:
    - vars/api.yml
    - vars/resources.yml
    - vars/ordering_org.yml

While all different ways are essentially the same, using vars_files has the following advantages:

  • reusable var declarations -- there are public arguments like api_endpoint, api_key etc that should be shared across playbooks.
  • simpler commands -- just ansible-playbook xxx.yaml now
  • version controlled record of vars files used -- providing a rough idea of where to find <DATA_FIELD> under specified task

note: the actual var/*.yaml files should be gitignored in production, but the file name included in the playbook is fine.


new edit: there is one scenario to use --extra-vars, when deploying multiple org each of which has the same playbook but different data.

for i in $(seq 1 10); do
  ansible-playbook 02-endorsing-org.yaml --extra-vars "@vars/org$i.yaml"
done
@sstone1
Copy link
Contributor

sstone1 commented May 29, 2020

This is a great idea @alxiong, I wasn't aware you could do this!

@sstone1 sstone1 self-assigned this May 29, 2020
@sstone1 sstone1 added the enhancement New feature or request label May 29, 2020
sstone1 pushed a commit to sstone1/ansible-collection that referenced this issue May 29, 2020
sstone1 pushed a commit to sstone1/ansible-collection that referenced this issue May 29, 2020
sstone1 pushed a commit to sstone1/ansible-collection that referenced this issue May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants