Ansible其实来自另一个主机

我试图从我另一个主持人那里得到一个事实:

- hosts: localhost tasks: - site_facts: name={{ var }} - hosts: "{{ apphost }}" tasks: - shell: command: docker inspect --format='\{\{.Image\}\}' {{ dbname }} register: imagehash - hosts: some_host tasks: - debug: var=hostvars[apphost].inventory_hostname - debug: var=hostvars['localhost'].inventory_hostname 

棘手的部分是'apphost'variables,通过–extra-vars传递,包含ec2上主机的标签名称。

然而hostvars列表使用ip adrress作为关键,所以我得到这个错误:

 fatal: [192.168.XX.XX] => Failed to template {{hostvars[apphost].inventory_hostname}}: host not found: tag_Name_docker1 

任何想法,我应该如何从这个主机得到事实?

适当的variables似乎是

  - debug: var=hostvars[groups[apphost][0]].inventory_hostname 

代替

  - debug: var=hostvars[apphost].inventory_hostname