I modified it to suit my hosts:

---
- name: test hostvars host1
  hosts: LBL
  tasks:
    - command: "ls /bin"
      register: ls_out

- name: test hostvars host2
  hosts: LM
  tasks:
    - debug:
        var: "{{ hostvars['LBL']['ls_out']['stdout'] }}"

and it doesn't work:

fatal: [10.104.148.138] => Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/ansible/runner/__init__.py", line 
590, in _executor
    exec_rc = self._executor_internal(host, new_stdin)
  File "/usr/lib/python2.6/site-packages/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 "/usr/lib/python2.6/site-packages/ansible/runner/__init__.py", line 
1004, in _executor_internal_inner
    complex_args = template.template(self.basedir, complex_args, inject, 
fail_on_undefined=self.error_on_undefined_vars)
  File "/usr/lib/python2.6/site-packages/ansible/utils/template.py", line 
133, in template
    d[k] = template(basedir, v, templatevars, lookup_fatal, depth, 
expand_lists, convert_bare, fail_on_undefined, filter_fatal)
  File "/usr/lib/python2.6/site-packages/ansible/utils/template.py", line 
119, in template
    varname = template_from_string(basedir, varname, templatevars, 
fail_on_undefined)
  File "/usr/lib/python2.6/site-packages/ansible/utils/template.py", line 
365, in template_from_string
    res = jinja2.utils.concat(rf)
  File "<template>", line 8, in root
  File "/usr/lib64/python2.6/site-packages/jinja2/environment.py", line 
331, in getitem
    return obj[argument]
  File "/usr/lib/python2.6/site-packages/ansible/runner/__init__.py", line 
103, in __getitem__
    result = self.inventory.get_variables(host, 
vault_password=self.vault_password).copy()
  File "/usr/lib/python2.6/site-packages/ansible/inventory/__init__.py", 
line 442, in get_variables
    raise Exception("host not found: %s" % hostname)
Exception: host not found: LBL

FATAL: all hosts have already failed -- aborting

the ls /bin is been executed but it's the same error
this is the content of my hosts file:

[LBL]
10.104.148.136
[LM]
10.104.148.138

What version of ansible are you running ?

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6b1be4e0-4112-4ba8-8a04-93a996cdff85%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to