I’m trying to move the fabric-based deployment process for one of our Python projects over to Ansible. In our current process, the provisioning stage is done manually. I’ve read a few tutorials and managed to migrate the first couple steps of the provisioning stage. But I’m stuck on getting Pythonbrew installed.
I suspect the problem has to do with the bash environment for the user, similar to the question posed here: .bashrc not being sourced
When I install Pythonbrew manually, I follow the steps here on the project page and then log out of my terminal and log back in.
Where is pythonbrew being installed? It would seem like you either need to add it to your PATH or to run the command through the full path to the executable.
When I ssh into the server as root (same user as in playbook) and run the same command, I don’t get the error. All I can figure is some contextual shell information is missing for the user when the playbook runs. I hoped the executable=/bin/bash flag would handle that but it doesn’t look like it.
So I whittled away at this and believe I finally got it figured out. A question persists.
As I suspected, solving the problem required getting the bash environment in the right state. I was able to install pythonbrew manually without logging out and in again (as is usually advised) by applying the equivalent of the following tasks:
Thank you Romeo and Michael for the pointing me to the environment keyword. Looking at the docs on it, however, it’s not clear to me how I would apply it to my case:
My impression from the docs is that the environment keyword functions something like a task-specific alternative to vars. It’s not clicking for me.
Perhaps someone with some experience using the environment keyword could demonstrate how to use it with the following code sample so as to eliminate the redundant export PYTHONBREW_ROOT=${pythonbrew.root}; source ${pythonbrew.root}/etc/bashrc; commands: