Ansible - use fact from local host in remote host template

与世无争的帅哥 提交于 2019-12-01 03:37:23

问题


I have a playbook that contains roles for localhost and roles for remote hosts.

In one of the localhost roles I set a fact called git_tag.

I want to use this fact in a template for the remote hosts.

I tried:

- name: Read Version
  set_fact:
    git_tag: "{{ package_json.stdout | from_json | json_query('version')}}"
  delegate_to: "test-server"

But when Ansible reaches the role that reads the template that has {{ git_tag }} it says that git_tag is undefined.

I'm sure I'm doing something wrong. How can I do it?


回答1:


You should use a hostvars magic variable:

{{ hostvars['localhost']['git_tag'] }}


来源:https://stackoverflow.com/questions/44885216/ansible-use-fact-from-local-host-in-remote-host-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!