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

group_vars/all not imported for implicit localhost when using dynamic inventory #6563

Closed
mark-casey opened this issue Mar 18, 2014 · 18 comments
Labels
bug This issue/PR relates to a bug. P1 Priority 1 - Immediate Attention Required; Release Immediately After Fixed

Comments

@mark-casey
Copy link

Issue Type:

Bug Report

Ansible Version:

ansible-playbook 1.5

Environment:

Ubuntu 12.04.4 LTS x64

Summary:

I think group_vars/all import is getting skipped for localhost when I specify a dynamic inventory. Here is console output of causing the issue:

Steps To Reproduce:
jenkins@ip-172-41-15-124:~/jobs/dev/workspace/bin/ansible/test-things$ ansible-playbook testgroupvars.yml

PLAY [Tests to make sure group_vars are getting imported] *********************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [Print a var] ***********************************************************
ok: [localhost] => {
    "foobar": "{{ foobar }}"
}

PLAY RECAP ********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0

jenkins@ip-172-41-15-124:~/jobs/dev/workspace/bin/ansible/test-things$ ansible-playbook -i test.py testgroupvars.yml

PLAY [Tests to make sure group_vars are getting imported] *********************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [Print a var] ***********************************************************
fatal: [localhost] => One or more undefined variables: 'mysql_root_password' is undefined

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
           to retry, use: --limit @/var/lib/jenkins/testgroupvars.retry

localhost                  : ok=1    changed=0    unreachable=1    failed=0

Here is a gist of related files: https://gist.github.com/mark-casey/9627855

Expected Results:

I would have expected the variable to be available in either use case but it wasn't.

Actual Results:

^^^

(edited to add actual template headings instead of just basing the content on template)

@mpdehaan mpdehaan added bug_report and removed P3 labels Mar 18, 2014
@MartinPeschke
Copy link

Ive been experiencing the same issue. Using ansible 1.6 and the ec2.py inventory from the docs,

This is anoying since it means one has to run against a dummy-inventory for some tasks:

 ansible-playbook -i LOCAL -u ubuntu provision.yml
 ansible-playbook -i ec2.py -u ubuntu terminate.yml

otherwise:

 ansible-playbook -i ec2.py -u ubuntu provision.yml

 PLAY [Stage instance(s)] ******************************************************
 TASK: [Provision a set of instances] ******************************************
 fatal: [localhost] => One or more undefined variables: 'number' is undefined
 FATAL: all hosts have already failed -- aborting

@mpdehaan mpdehaan added P5 and removed P4 labels Apr 17, 2014
@faraocious
Copy link

I'm seeing a similar things with a dynamic inventory script modified from the ec2.py file.

I'm ending up with undefined vars during execution. I was reading elsewhere (#3566) this is due to passing an inline list instead of a file, possibly? just trying to get to the root of the issue.

@mpdehaan mpdehaan added P2 and removed P5 labels Aug 7, 2014
@quentinsf
Copy link
Contributor

Yes, I'm seeing something probably related - I have default values for variables defined in the 'defaults' directories within roles, but I can't overwrite them using group_vars if the hosts & groups come from ec2.py. The only way is to override on the command line with '-e'.

I've tried this both with the tag_name_value groups that are automatically created, and with hosts that have been put into groups using add_host. Will try to put together a minimal demo case.

@quentinsf
Copy link
Contributor

More details on what i think is a related issue at #8605 .

@mpdehaan
Copy link
Contributor

That's not related. Will comment seperately on that post.

@mpdehaan mpdehaan added P1 and removed P2 labels Aug 18, 2014
jimi-c added a commit to jimi-c/ansible that referenced this issue Aug 18, 2014
@jimi-c jimi-c closed this as completed in e389584 Aug 18, 2014
@jimi-c
Copy link
Member

jimi-c commented Aug 18, 2014

Closing This Ticket

Hi!

We believe the above commit should resolve this question or 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!

@ghost
Copy link

ghost commented Aug 25, 2014

Thanks... I just ran into a case where I hit this bug :D

And I realized I hadn't git-pulled in a bit of time.

@danielsiwiec
Copy link

Seems like this issue still affects Ansible 1.7.2:
I'm running the debug module with the inventory passed either through a file or dynamically. In the latter option, the variable is not picked up.

[dsiwiec@NAdsiwiec /tmp]$ ansible --version
ansible 1.7.2

[dsiwiec@NAdsiwiec /tmp]$ more inv
192.169.0.10

[dsiwiec@NAdsiwiec /tmp]$ more group_vars/all.yml
my_var: Hello, I'm group var

[dsiwiec@NAdsiwiec /tmp]$ ansible all -m debug -a var=my_var -i inv
192.169.0.10 | success >> {
    "my_var": "Hello, I'm group var"
}

[dsiwiec@NAdsiwiec /tmp]$ ansible all -m debug -a var=my_var -i "192.169.0.10,"
192.169.0.10 | success >> {
    "my_var": "{{ my_var }}"
}

@sankalp-khare
Copy link
Contributor

@danielsiwiec , I think this is intentional. The ad-hoc inventory method that you used the second time around doesn't support grouping of hosts (naturally, since it's a hack and not the standard method of specifying inventory), while group_vars/all.yml is clearly something that is loaded when the notion of groups comes into play.

Just my two cents. It might be wise to have this verified by someone who knows about this more deeply.

@danielsiwiec
Copy link

Hmm. My understanding was that the dynamically specified hosts are assigned the all group, like it is with the inventory file in case you don't enclose the host with a group tag (vide my first invocation of ansible). This is also how the dynamic inventory works for the ansible-playbook command, where the host is clearly matched with the all group:

[dsiwiec@NAdsiwiec /tmp]$ more playbook.yml
- hosts: all
  gather_facts: false
  tasks:
    - debug: var=my_var

[dsiwiec@NAdsiwiec /tmp]$ ansible-playbook playbook.yml -i "192.169.0.10,"

PLAY [all] ********************************************************************

TASK: [debug var=my_var] ******************************************************
ok: [192.169.0.10] => {
    "my_var": "Hello, I'm group var"
}

PLAY RECAP ********************************************************************
192.169.0.10    : ok=1    changed=0    unreachable=0    failed=0

@sheldonh
Copy link
Contributor

Could someone clarify?

Given this group_vars/all:

---
foo: bar

And this playbook called test.yml:

---
-
  hosts: localhost
  connection: local
  tasks:
    -
      debug: msg="{{ foo }}"

Should this command error out with 'foo' is undefined?

ansible-playbook -i /dev/null test.yml

It errors for me with 2.0.0 (devel 6971e92).

@jimi-c
Copy link
Member

jimi-c commented Jul 14, 2015

@sheldonh the loading of group_vars is generally dependent on the inventory location, though it should also look relative to the current working path, so this may be a bug. Please open a new issue for this.

@bcoca
Copy link
Member

bcoca commented Jul 14, 2015

by 'working path' james means adjacent to the play called:

 play.yml
 group_vars/all

@jimi-c
Copy link
Member

jimi-c commented Jul 14, 2015

Yes, what we call internally the basedir usually.

@jimi-c
Copy link
Member

jimi-c commented Jul 14, 2015

@sheldonh I went ahead and fixed this already:

commit 4e94bb64d82eeb8756ff54f208f001c1056a12bd
Author: James Cammarata 
Date:   Tue Jul 14 09:26:24 2015 -0400
    Fix group/host var loading relative to playbook basedir

@sheldonh
Copy link
Contributor

Works for me, thanks.

@tamsky
Copy link
Contributor

tamsky commented Nov 4, 2015

Both commits on this issue are only to the devel/v2 branch:
e389584
4e94bb6
Anyone know if these patches work on v.1.9.x?

@matajaz
Copy link

matajaz commented May 26, 2016

I just experience this problem on ansible-playbook 2.0.2.0
My playbook works on my laptop but when run the same playbook on a vm in a cloud all group_vars are undefined.
I updated the ansible.cfg in the cloud to set the same config params as I had on my laptop (the default ones) but it did not make any difference. It still does not work in my cloud.
Are there any configuration parameter to enable/disable group_vars?

Br Mathias

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 6, 2018
@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
bug This issue/PR relates to a bug. P1 Priority 1 - Immediate Attention Required; Release Immediately After Fixed
Projects
None yet
Development

No branches or pull requests