Ansible - use fact from local host in remote host

2020-03-23 18:12发布

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条回答
够拽才男人
2楼-- · 2020-03-23 18:39

You should use a hostvars magic variable:

{{ hostvars['localhost']['git_tag'] }}
查看更多
登录 后发表回答