Pass Ansible variable to remote host

47 views
Skip to first unread message

Mladen Stankovic

unread,
Aug 22, 2017, 9:13:28 AM8/22/17
to Ansible Project
Hi,

I am trying to pass a variable defined in Ansible host to a remote host, using lookup plugin native hashi_vault, but play returns an error that variable is not defined. 
The same variable returns expected value on the localhost but not on the remote host. Folowing command was used: {{ hostvars['localhost']['vault_pass'] }} but without no luck.

Can you please advise the best way to obtain variable from Ansible lookup plugin, and use it on the remote host? I am aware that lookup plugin executes only on Ansible host.

BR,
Mladen

Kai Stian Olstad

unread,
Aug 25, 2017, 4:43:08 PM8/25/17
to ansible...@googlegroups.com
On tirsdag 22. august 2017 15.13.28 CEST Mladen Stankovic wrote:
> I am trying to pass a variable defined in Ansible host to a remote host,
> using lookup plugin *native hashi_vault*, but play returns an error that
> variable is not defined.
> The same variable returns expected value on the localhost but not on the
> remote host. Folowing command was used: *{{
> hostvars['localhost']['vault_pass'] }} *but without no luck.
>
> Can you please advise the best way to obtain variable from Ansible lookup
> plugin, and use it on the remote host? I am aware that lookup plugin
> executes only on Ansible host.

The lookup plugin will run on the ansible controller but the result will be
per host.

Let's say we have this playbook

- hosts: all
vars:
motd: "{{ lookup('file', '/etc/motd') }}"

All the host in the inventory will now have a variable called motd that
contains the content of the /etc/motd on the Ansible controller.


--
Kai Stian Olstad

Mladen Stankovic

unread,
Aug 28, 2017, 8:46:30 AM8/28/17
to Ansible Project
Hi,

thank you very match for your comment. I have created new inventory file with one server and accomplished what I want.

BR,
Mladen  
Reply all
Reply to author
Forward
0 new messages