I’m trying to manage services via Ansible but I’m getting an error because python is not installed in the manager machines.
I’ve tried to install via sources but I’m getting this error:
~/Python-2.7.12 $ ./configure
-sh: can’t fork
How can I install it?
Edit: I’ve seen that apk is available to install packages but I need root permissions, how can I get it?
Generally, you should try to run stuff in containers. Eg. you can grab a container on Docker for AWS with the userland you want. You can even volume-mount the Docker socket if you need your python script to start and stop containers.
Alternatively, you can setup a SSH tunnel to your local environment (which I suspect has Python) and run you script against your Docker for AWS swarm: https://beta.docker.com/docs/deploy/
I want to use Ansible as automation tool to create, scale and remove services (Ansible will launch docker service create, docker service rm, etc).
Ansible uses modules, some of those modules are written in Python so Ansible needs python in the manager machine to be able to execute his own scripts.
Regarding to your answer I don’t know how to fit a python container with my needs, can you show me an example?
I’ve figured out how to use Ansible without Python, there is a module called raw module that allows bash commands execution, so there is no need for python. Anyway it will be great to use python modules.
I want to execute this command: docker service update --image latest redis
Ansible has playbooks, so if I configure manager ssh connection within the playbook and I set this command as a task, I can execute from jenkins: ansible-playbook redis-update.yml
And it will connect via ssh and executes the service update command in the manager.
Alright, so it looks like the only thing to be executed on the manager is docker service update --image latest redis - why is Python required for that (sorry if I’m being dense, just trying to understand your use case so that we can better support it).
Python is required by Ansible playbooks and modules to be present in remote machines. i.e.: Ansible has a core module called ping written in python, so when you execute ansible -m ping, Ansible executes an internal python script in the remote machine to make ping and get a response.
Using Ansible inside a container works really well for this use case (we use it like this all the time). You can even have your own Ansible image which will contain all your roles and playbooks. You’ll then use this container to run Ansible commands, so the container is not a long living service but more like a CLI tool.
you could use the raw module to install python and then use the rest of the modules like normal. xenial removed python 2.7, so you need to add it back in order for ansible to work again (trusty does’t have this issue). you use the raw module to ‘apt-get install -y python’ when given a variable (i use bootstrap_os: xenial in my group_vars file), and then you can use ansible as normal for everything else.
not sure if this helps, or if you’ve already solved it. sorry if this didn’t provide any extra help.