you have the environment: keyword that can set path per task, in 1.9
you can do it per play.
I’m having problems with some hosts running ansible: It complains that there is no simplejson module found. I figured that it is something to do with the way ansible_env.PATH is set as somehow it picks up a very old version of python and i can’t figure out where it comes from. I posted the question on stackoverflow and found this thread and other people asking the same thing - but there is still no definitive answer.
I would like to know how this variable is getting set and how i can affect it to make sure that the right version of python is used on the host?
http://stackoverflow.com/questions/29289472/ansible-how-ansible-env-path-is-set-in-ssh-session
http://grokbase.com/t/gg/ansible-project/1479n0d0qp/ansible-env-path-how-is-it-set
thanks a lot!
It’s been my experience that ansible absolutely requires Python 2.6+ or Python 2.4 with the simplejson module. I don’t know where in the documents, but I reference this in my README for my main ansible project:
https://github.com/stevenhaddox/ansible_rails_enterprise/blob/master/README.md
I also handle it in my init.yml & as my first step for any server:
https://github.com/stevenhaddox/ansible_rails_enterprise/blob/master/provisioning/init.yml
# Spin-up the VM and bootstrap the server to add python-simplejson & needed packages
$ vagrant up --no-provision && ansible-playbook provisioning/init.yml -i provisioning/hosts/vagrant -u vagrant -s
ansible_env.PATH is a reflection of the PATH variable on the system
when ansible gathered facts, ansible does not set the path in a
special maner. The PATH is set by the host as it would for any other
non login process (not sourcing .bashrc or other shell equivalents).
If you are having issues using the correct python try setting
ansible_python_interpreter for that host to the correct python.
yes, i have misstated the problem in my initial question a bit, sorry.
I know about the ansible_python_interpreter and it does take care of the simplejson error, as instead of using the interpreter that is available in PATH it uses what i have specified.
So the only question about that variable right now for me is if this can be set globally? I’ll take a look at the ansible.cfg related docs.
as for the PATH or ansible_env.PATH my current understanding is that the idea is to avoid creation of playbooks that might depend too heavily on t the PATH and therefore may become error prone. The way to change though is through “environment: PATH”.
Am I correct?
Thanks!
yes, environment is now settable at task/play level, I have it on my
list to add either a global (ansible.cfg) or inventory setting
Hi Brian Coca
Set PATH variable like this in play level work well for me,
environment:
PATH: “{{ ansible_env.PATH }}:/usr/local/bin”
I just wonder how you set this in global or inventory setting? Can you show me an example of inventory setting?
its still on my 'todo' list, cannot show examples until it transitions
to my 'done' list
Hi Brian,
Has there been any update on setting ansible_python_interpreter in ansible.cfg.
Our use case is
Inside a system user account, we have our own python 2.7.6 version and we want to use ansible_python_interpreter to set our own python path not the one comes by default.
Regards,
Osama -
You can set the python interpreter as a host or group var. Normally I set
ansible_python_interpreter: /usr/bin/env python
But in your case it sounds like you’d want a specific path.