Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set environment variables of remote hosts

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.

like image 309
mndhr Avatar asked Mar 28 '16 10:03

mndhr


1 Answers

You can set the PATH for a task or a playbook by using the environment keyword.

environment:
  PATH: "{{ ansible_env.PATH }}:/thingy/bin"
  SOME: value

The Ansible FAQ mentions this near the top http://docs.ansible.com/ansible/faq.html

So in your case try something like the following:

- name: Set Path for java
  environment:
    PATH: "$JAVA_HOME/bin:{{ ansible_env.PATH }}"

Setting the environment reference: http://docs.ansible.com/ansible/playbooks_environment.html

like image 184
wazy Avatar answered Oct 23 '22 04:10

wazy