How to setup PATH variable in an Ansible task using the environment module?

25 views
Skip to first unread message

ZillaYT

unread,
Oct 25, 2017, 11:36:13 AM10/25/17
to Ansible Project
I'm running Ansble v2.4.0.0 in a RHEL7.2 box.

I'm trying to setup the PATH variable with the following simple task, but I'm getting a syntax error.

tasks/main.yml
--------------

---
- name: Append to PATH variable
  environment
:
    PATH
: /usr/some_other/bin:{{ ansible_env.PATH }}

...or...

tasks/main.yml
--------------

---
- name: Append to PATH variable
  environment
:
    PATH
: /usr/some_other/bin:{{ lookup('env','PATH') }}

Both give me syntax errors. What is the correct way to do this?

Brian Coca

unread,
Oct 25, 2017, 11:45:13 AM10/25/17
to Ansible Project
environment is NOT a module, its a keyword that test the environment
for your task/action.

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

ZillaYT

unread,
Oct 25, 2017, 11:59:34 AM10/25/17
to Ansible Project

ZillaYT

unread,
Oct 25, 2017, 1:26:44 PM10/25/17
to Ansible Project
I asked the same question in Stack Overflow How to set existing linux environment variables with ansible? and the answer there makes sense, which is the same answer Brian was alluding to. Thanks!
Reply all
Reply to author
Forward
0 new messages