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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With