ansible 2.0.1 environement variables of remote host

59 views
Skip to first unread message

mondher khas

unread,
Mar 31, 2016, 6:45:06 AM3/31/16
to Ansible Project
environment variables
  • Hello , i use ansible to run tasks in remote machine , i want to work with variables from this remote machine . i tried to use lookup module but it return the variables of my machine to the remote one . i have no idea haw to do it . 
  • i itried to use "{{ ansible_env.PATH }}" but it return the PATH of my machine . i want to have the PATH of the remote host mentioned in the file /etc/ansible/hosts not the Path of my machine in which i installed ansible

  • thanks in advance. 
ANSIBLE VERSION
  • 2.0.1
CONFIGURATION
  • /etc/ansible/ansible.cfg (configuration) 
  • /etc/ansible/hosts (list of remote hosts)
OS / ENVIRONMENT
  • CentOS 7

Brian Coca

unread,
Mar 31, 2016, 10:16:44 AM3/31/16
to ansible...@googlegroups.com
ansible_env reflects the facts on the machine you gathered facts on, so if it is showing localhost values, you ONLY gathered facts on localhost.

this should show the path for EACH machine:

hosts: all
tasks:
  - debug: msg="{{ansible_env.PATH}}" 



----------
Brian Coca

mondher khas

unread,
Mar 31, 2016, 12:15:44 PM3/31/16
to Ansible Project
so , i must gather facts off all hosts , that's the solution ? 

Brian Coca

unread,
Mar 31, 2016, 4:17:50 PM3/31/16
to ansible...@googlegroups.com
no, just on the hosts you want to use facts from.

​that was an example that would show you the facts per host, 'all' is the only group i know you have for sure.​

----------
Brian Coca

mondher khas

unread,
Apr 4, 2016, 4:23:33 AM4/4/16
to Ansible Project
to work with the PATH of the remote host i add those lines to my playbook ? 
- gather_facts: yes 
vars: 

 PTH : "{{ansible_env.PATH}}"
 
is that correct ? 
thank you in advance .
i' m a begginer at ansible .
----------
khaskhoussi mondher 
Reply all
Reply to author
Forward
0 new messages