Ansible - use fact from local host in remote host template

Viewed 4001

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?

2 Answers

you can use this

{{ hostvars['test-server']['git_tag'] }}

Related