Last active
August 29, 2015 14:20
-
-
Save rektide/c83208ccf4ab84638546 to your computer and use it in GitHub Desktop.
Zomgwtfbbq Ansible what happened to hostvars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PLAY [all] ******************************************************************** | |
TASK: [debug msg="{{ vars }}"] ************************************************ | |
ok: [127.0.0.1] => { | |
"msg": "{'delegate_to': None, 'failed_when': None, 'inventory_file': '/etc/opt/ansible-git/hosts/default', 'playbook_dir': '/home/rektide/projects/compfuzor', 'register': None, 'inventory_dir': '/etc/opt/ansible-git/hosts', 'always_run': False, 'HI': 'yes hello', 'role_names': [], 'play_hosts': ['127.0.0.1'], 'ignore_errors': False, 'changed_when': None}" | |
} | |
TASK: [debug msg="{{ hostvars }}"] ******************************************** | |
ok: [127.0.0.1] => { | |
"msg": "{'127.0.0.1': {}}" | |
} | |
TASK: [debug msg="ofc, {{ vars['HI']|default('WORKED IN 1.7.x') }}"] ********** | |
ok: [127.0.0.1] => { | |
"msg": "ofc, yes hello" | |
} | |
TASK: [debug msg="ofc, {{ hostvars['HI']|default('debug of hostvars makes this look like it would work') }}"] *** | |
fatal: [127.0.0.1] => host not found: HI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PLAY [all] ******************************************************************** | |
TASK: [debug msg="{{ vars }}"] ************************************************ | |
ok: [127.0.0.1] => { | |
"msg": "{'delegate_to': None, 'failed_when': None, 'inventory_file': '/etc/opt/ansible-git/hosts/default', 'playbook_dir': '/home/rektide/projects/compfuzor', 'register': None, 'inventory_dir': '/etc/opt/ansible-git/hosts', 'always_run': False, 'changed_when': None, 'role_names': [], 'play_hosts': ['127.0.0.1'], 'ignore_errors': False, 'ansible_version': {'major': 1, 'full': '1.8.2', 'string': '1.8.2 (detached HEAD 986012996f) last updated 2015/05/05 21:07:34 (GMT -400)\\n lib/ansible/modules/core: (detached HEAD 54ee8aa8e8) last updated 2015/05/05 21:07:35 (GMT -400)\\n lib/ansible/modules/extras: (detached HEAD c60441fddd) last updated 2015/05/05 21:07:35 (GMT -400)\\n v2/ansible/modules/core: (detached HEAD cb69744bce) last updated 2014/10/11 17:47:41 (GMT -400)\\n v2/ansible/modules/extras: (detached HEAD 8a4f07eecd) last updated 2014/10/11 17:47:45 (GMT -400)\\n configured module search path = /opt/ansible-git/library:/usr/share/ansible/', 'minor': 8, 'revision': 2}}" | |
} | |
TASK: [debug msg="{{ hostvars }}"] ******************************************** | |
ok: [127.0.0.1] => { | |
"msg": "{'inventory_hostname_short': '127', 'inventory_hostname': '127.0.0.1', 'HI': 'yes hello', '127.0.0.1': {}, 'group_names': ['ungrouped']}" | |
} | |
TASK: [debug msg="ofc, {{ vars['HI']|default('WORKED IN 1.7.x') }}"] ********** | |
ok: [127.0.0.1] => { | |
"msg": "ofc, WORKED IN 1.7.x" | |
} | |
TASK: [debug msg="ofc, {{ hostvars['HI']|default('debug of hostvars makes this look like it would work') }}"] *** | |
fatal: [127.0.0.1] => Traceback (most recent call last): | |
File "/opt/ansible-git/lib/ansible/runner/__init__.py", line 590, in _executor | |
exec_rc = self._executor_internal(host, new_stdin) | |
File "/opt/ansible-git/lib/ansible/runner/__init__.py", line 792, in _executor_internal | |
return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args) | |
File "/opt/ansible-git/lib/ansible/runner/__init__.py", line 993, in _executor_internal_inner | |
module_args = template.template(self.basedir, module_args, inject, fail_on_undefined=self.error_on_undefined_vars) | |
File "/opt/ansible-git/lib/ansible/utils/template.py", line 116, in template | |
varname = template_from_string(basedir, varname, templatevars, fail_on_undefined) | |
File "/opt/ansible-git/lib/ansible/utils/template.py", line 362, in template_from_string | |
res = jinja2.utils.concat(rf) | |
File "<template>", line 10, in root | |
File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 378, in getitem | |
return obj[argument] | |
File "/opt/ansible-git/lib/ansible/runner/__init__.py", line 103, in __getitem__ | |
result = self.inventory.get_variables(host, vault_password=self.vault_password).copy() | |
File "/opt/ansible-git/lib/ansible/inventory/__init__.py", line 442, in get_variables | |
raise Exception("host not found: %s" % hostname) | |
Exception: host not found: HI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: all | |
gather_facts: False | |
vars: | |
HI: 'yes hello' | |
tasks: | |
- debug: msg="{{ vars }}" | |
- debug: msg="{{ hostvars }}" | |
# in 1.8.2+, HI begins to appear in hostvars, but not under a host | |
- debug: msg="ofc, {{ vars['HI']|default('WORKED IN 1.7.x') }}" | |
- debug: msg="ofc, {{ hostvars['HI']|default('debug of hostvars makes this look like it would work') }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
once upon a time, line #3 would have returned
yes hello
but now it looks like HI is bound to hostvars? that's new. And when we go to gethostvars['HI']
we get a fatal exception, even though line #1 tells us hi is there now.