haw to get environement variables of remote host ansible 2.0.1

2,947 views
Skip to first unread message

mondher khas

unread,
Apr 4, 2016, 9:55:26 AM4/4/16
to Ansible Project

I am having problems working with the environment variables of a remote host. For example, when I try {{ lookup('env', 'PATH') }} this returns the path of my guest machine not of the remote host.

How to pick up / change environment variables of the remote host?

my playbook :

---
- name : playbook
  hosts : webservers
  gather_facts: yes
  remote_user: user1
  vars:
   Path: "{{lookup('ansible_env','PATH')}}"
  roles :
 - task1
 - task2 
 - task3 

that's return the path of my machine not the path of remote host named user1 i'm a beginner in ansible need some help . thank you in advance.

and i tried to use just "{{ ansible_env.PATH}}" but still return to me the same Path of my local machine . i tried to get other variable like still return emty "" or return the value of the variable if it defined in my local machine . and i tried to discover all the ansible_env variables in the remote host with the command 
ansible all -m setup i can't find all the variable defined in the remote host .

Brian Coca

unread,
Apr 4, 2016, 10:20:49 AM4/4/16
to ansible...@googlegroups.com
{{ansible_env.PATH}} should return the path of the 'inventory_hostname', there is no lookup('ansible_env' ..).

try using `debug: var=ansible_env` to make sure you are gathering facts where you expect.


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

mondher khas

unread,
Apr 4, 2016, 10:41:27 AM4/4/16
to Ansible Project

 `debug: var=ansible_env` works very well . but it's return some variables not all the variable of my remote host . is there some truc that make those variables invisible because i couldn't see them all ?? 

Brian Coca

unread,
Apr 4, 2016, 11:42:32 AM4/4/16
to ansible...@googlegroups.com
There are several reasons for this, first Ansible logs in as a particular user so that already narrows down the environment varialbes. It also avoids doing an interactive login, which avoids source .bashrc and other like files. 

If you add in privilege escalation (sudo/su/etc), this also affects the variables available as they normally modify them for security reasons.


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

mondher khas

unread,
Apr 4, 2016, 11:48:33 AM4/4/16
to Ansible Project
thank you brian for your quick ansewer  , do you know  haw to be able to change or access to those variable .have you any idea ? 
----------
khaskhoussi mondher 
Reply all
Reply to author
Forward
0 new messages