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

Playbook variables ignored when used vars_files + inventory_dir #12633

Closed
yrybak opened this issue Oct 5, 2015 · 7 comments
Closed

Playbook variables ignored when used vars_files + inventory_dir #12633

yrybak opened this issue Oct 5, 2015 · 7 comments
Labels
bug This issue/PR relates to a bug.
Milestone

Comments

@yrybak
Copy link

yrybak commented Oct 5, 2015

Issue Type: Bug Report
Ansible Version: 1.9.1-1.9.3
Ansible Configuration: default
Environment: Ubuntu 14.04.2 LTS
Summary:

Variables are ignored if provided through "vars_files" playbook parameter with file name containing {{inventory_dir}} magic variable.

If file name is provided as static path - no issue.
Also, if include playbook into another playbook and run - no issue.

There was similar issue #8638 fixed, and its commit is included in tags since release 1.8. Though, our scenario is very similar, but doesn't work.

Steps To Reproduce:

We have several environments defined in the repository in different folders - "dev", "staging", "production". So, depending on environment we may run playbook with "-i dev/inventory" or "-i staging/inventory" etc. So we want to use "{{ inventory_dir }}" variable to get correct path to variables file.

Test variable file (place to dev/group_vars/test.yml):


---
file_var: file_var_value

Test playbook (place to test-file-vars.yml):


---
- name:   Test file variables
  hosts:  localhost
  vars_files:
    - "{{ inventory_dir }}/group_vars/test.yml"
#    - "dev/group_vars/test.yml" # such static path works
  tasks:
    - debug: msg="variable {{ file_var }}"

Code to run:

$ ansible-playbook -i dev/inventory test-file-vars.yml

We see that file path is validated correctly, but its variables are missing.
Static file path works well, but that doesn't allow us to parametrize environment.
When include playbook above into another playbook, everything works well.

Expected Results:

Debug message should be

"msg": "variable file_var_value"
Actual Results:

Getting error:

fatal: [localhost] => One or more undefined variables: 'file_var' is undefined
@jimi-c jimi-c added this to the v2 milestone Oct 5, 2015
@jimi-c jimi-c closed this as completed in d91b3c6 Oct 5, 2015
@jimi-c
Copy link
Member

jimi-c commented Oct 5, 2015

Closing This Ticket

Hi!

We believe the above commit should resolve this problem for you. This will also be included in the next major release.

If you continue seeing any problems related to this issue, or if you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:

Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved.

Thank you!

@dene14
Copy link

dene14 commented Dec 3, 2015

Ansible 1.9.4 affected as well

I like the way ansible maintainers solving the issues in... I have already found like 10 dependency cycles when you're going through the chain:

  1. "you doing the stuff wrong", please do this in a different way
  2. different way, works differently, your stuff doesn't fit it, please use workaround
  3. workaround doesn't work... just because.
  4. fix proposed and merged
  5. fix reverted, like 5 other features just bombed out
  6. close with won't fix
  7. reopen "guys we really want that fixed"
  8. added to the 2.0 milestone

For those who are frustrated as well and want at least a silly workaround right away:
Create another playbook with only this stuff inside:

---
- include: your_playbook.yml

This will load vars_files as expected.

@jimi-c
Copy link
Member

jimi-c commented Dec 3, 2015

@dene14 leaving the same comment on multiple closed issues is not helpful. If you're having a problem, please open a new issue or email one of the mailing lists to discuss it.

@dene14
Copy link

dene14 commented Dec 3, 2015

jimi-c, I feel like there is no much sense to do it. I will see "Closing This Ticket" message in the end of a thread quite soon-ish :)

@jimi-c
Copy link
Member

jimi-c commented Dec 3, 2015

We take all issues seriously. In both issues you commented on, the problem was fixed and neither reporter took issue with the fix (In fact, in #8638 akuznecov confirmed the problem was resolved), so we're not going to address this further.

@yrybak
Copy link
Author

yrybak commented Dec 3, 2015

As fix for this issue is applied to devel branch and v2.0 tags, and I am still using 1.9, I had no chance to verify that. Though I use workaround with "include_vars" module in 1.9.

@msieurtoph
Copy link

@dene14 Thanks for the workaround.
It is frustrating not to have the existing 2.0's fix in the 1.9 version.

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

5 participants