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

host_vars variables #32466

Closed
djadk84 opened this issue Nov 1, 2017 · 3 comments
Closed

host_vars variables #32466

djadk84 opened this issue Nov 1, 2017 · 3 comments
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@djadk84
Copy link

djadk84 commented Nov 1, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

host_vars variables

ANSIBLE VERSION
ansible 2.4.1.0
  config file = /home/user/.ansible.cfg
  configured module search path = [u'/home/user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14 (default, Sep 20 2017, 01:25:59) [GCC 7.2.0]```
CONFIGURATION
$ ansible-config dump --only-changed
ALLOW_WORLD_READABLE_TMPFILES(/home/user/.ansible.cfg) = True
ANSIBLE_PIPELINING(/home/user/.ansible.cfg) = True
CACHE_PLUGIN(/home/user/.ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/user/.ansible.cfg) = ~/.facts_cache
CACHE_PLUGIN_TIMEOUT(/home/user/.ansible.cfg) = 7776000
COLOR_OK(/home/user/.ansible.cfg) = green
DEFAULT_FORKS(/home/user/.ansible.cfg) = 12
DEFAULT_GATHERING(/home/user/.ansible.cfg) = smart
DEFAULT_GATHER_SUBSET(/home/user/.ansible.cfg) = all
DEFAULT_HOST_LIST(/home/user/.ansible.cfg) = [u'/etc/ansible/inventory']
DEFAULT_LOCAL_TMP(/home/user/.ansible.cfg) = /tmp/.ansible/tmp/ansible-local-13276EAtgsC
DEFAULT_MODULE_COMPRESSION(/home/user/.ansible.cfg) = ZIP_DEFLATED
DEFAULT_REMOTE_TMP(/home/user/.ansible.cfg) = ~/.ansible/tmp
DEFAULT_SCP_IF_SSH(/home/user/.ansible.cfg) = smart
DEFAULT_TIMEOUT(/home/user/.ansible.cfg) = 60
MERGE_MULTIPLE_CLI_TAGS(/home/user/.ansible.cfg) = True
RETRY_FILES_ENABLED(/home/user/.ansible.cfg) = True
RETRY_FILES_SAVE_PATH(/home/user/.ansible.cfg) = /tmp/.ansible-retry
OS / ENVIRONMENT
$ uname -a
Linux  4.13.9-1-ARCH #1 SMP PREEMPT Sun Oct 22 09:07:32 CEST 2017 x86_64 GNU/Linux
SUMMARY
I have some variable declare in host_vars and I'm trying to query some specific variable from other inventory_hostname using hostvars, Im getting an error. but if I copy those variable in my inventory directory it works.
STEPS TO REPRODUCE
cat host_vars/server2.yml
---
variable2: this is another variable
cat host_vars/server1.yml
---
variable1: this is a variable
$ ansible server1 -m debug -a"msg={{ hostvars['server2']['variable2'] }}"
EXPECTED RESULTS
$ ansible server1 -m debug -a"msg={{ hostvars['server2']['variable1'] }}" -vvv
ansible 2.4.1.0
  config file = /home/user/.ansible.cfg
  configured module search path = [u'/home/user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14 (default, Sep 20 2017, 01:25:59) [GCC 7.2.0]
Using /home/user/.ansible.cfg as config file
Parsed /etc/ansible/inventory/hosts inventory source with ini plugin
META: ran handlers
server1 | SUCCESS => {
    "msg": "this is another variable"
}
META: ran handlers
META: ran handlers
ACTUAL RESULTS
$ ansible server1 -m debug -a"msg={{ hostvars['server2']['variable2'] }}" -vvv
ansible 2.4.1.0
  config file = /home/user/.ansible.cfg
  configured module search path = [u'/home/user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14 (default, Sep 20 2017, 01:25:59) [GCC 7.2.0]
Using /home/user/.ansible.cfg as config file
Parsed /etc/ansible/inventory/hosts inventory source with ini plugin
META: ran handlers
server1 | FAILED! => {
    "failed": true, 
    "msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'variable2'\nexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'dict object' has no attribute 'variable2'"
}
@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug_report needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Nov 1, 2017
@jborean93
Copy link
Contributor

Is This A Bug?

Hi!

Thanks very much for your submission to Ansible. It sincerely means a lot to us.

We're not sure this is a bug, and we don't mean for this to be confrontational. Let's explain what we're thinking:

  • When using the ansible executable, host_vars and group_vars are loaded from the same directory as the inventory file itself
  • If you were to copy the host_vars folder to /etc/ansible/inventory Ansible will be able to pick up the hostvars
  • If using the ansible-playbook executable, host_vars and group_vars are also loaded from the same directory as the playbook file being run

As such, we're going to close this ticket. However, we're open to being corrected, should you wish to discuss. You can stop by one of our two mailing lists
to talk about this and we might be persuaded otherwise.

Comments on closed tickets aren't something we monitor, so if you do disagree with this, a mailing list thread is probably appropriate.

Thank you once again for this and your interest in Ansible!

@djadk84
Copy link
Author

djadk84 commented Nov 2, 2017

@jborean93 looks like you misunderstood my explanation, this was working in the previous version of ansible those variables where define in host_vars. and didn't have any issue with it. This only happens after I have updated ansible and was trying to update a server. I only copied host_vars to inventory directory as a debugging effort. It seems for me I'm unable to query variable in host_vars directory using hostvars Not sure why it happens but you can give it a try and see for yourself if you have the time.

@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Nov 2, 2017
@bcoca
Copy link
Member

bcoca commented Nov 2, 2017

dupe of #31755 and #31758, fixed by #32269, should be in 2.4.2 release

@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 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

No branches or pull requests

4 participants