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

roles do not allow to access vars from dynamically loaded vars_files when var is prompted #4445

Closed
vsaisha opened this issue Oct 11, 2013 · 1 comment

Comments

@vsaisha
Copy link

vsaisha commented Oct 11, 2013

Hi,
I have observed the following behavior in the following scenario.

var files

vars/static.yml
config_names:
- value1
- value2

vars/test.yml
config_names:
- value3
- value4

playbook

vars_prompt:
- name: "filename"
prompt: "Filename"
private: no
when: filename is not defined
vars_files:
- vars/static.yml
- [ vars/ {{ filename }}. yml, vars/static.yml ]

pre_tasks:
- debug: msg="{{ item }}"
with_items: config_names
roles:
- { role: test, with_items: config_names }
post_tasks:
- debug: msg="{{ item }}
with_items: config_names

Execution 1:

  ansible-playbook -i test.yml playbook.yml -e 'filename=test"

Result:
No prompt.
vars/test.yml would loaded in order
pre_tasks, roles, post_tasks are printing config_names value from test.yml as expected.

Execution 2:

  ansible-playbook -i test.yml playbook.yml

Result:
Prompts for filename.
pre_tasks and post_tasks are printing config_names value from test.yml
roles is using value from vars/static.yml file.

Summary

Some how the workflow is missing to consider prompted variable values for roles section ( not sure of underneath task ). My case is more complex, I have split up prompt and tasks into two different playbooks and included in sequential order in top playbook. The first playbook prompts and set variables using set_fact task. The second playbook would be called after executing the first, so as expected the verbose shows of loading right file then using right values in pre and post tasks. Roles failed to recognize the overridden value.

Cheers
Venkat Vagga

@mpdehaan
Copy link
Contributor

It's impossible in Ansible for variables to work in every possible resolution order someone would want.

Sometimes they might want variables in vars_files to appear in vars prompt messages, etc.

What I would suggest here seeing you are passing in a filename is to pass it in via -e

-e "filename=foo.yml" on the Ansible command line will help here.

@ansible ansible locked and limited conversation to collaborators Apr 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants