Using ansible to manage services

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.

Thank you for your answer.

How about running ansible in a container?

docker run -ti williamyeh/ansible:1.9-ubuntu12.04 bash

I don’t want to execute Ansible inside the manager, I want to run Ansible from jenkins to create a friendly CLI to create, remove or scale services.

Got it, thanks - out of curiosity, what is it that you would like to run on the manager?

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).

No problem.

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.

1 Like

Thank you for your answer.
I will try your solution which is similar to Michael’s solution.

Edit: How do you connect to the manager? Using some CI tool, manually?

I forgot to thank you for your answers.

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.

Docker for AWS AMI does not provide permissions to install via apt-get, yum, aptitude or apk so this solution is not possible :sob:

ah, i misunderstood entirely.

Running Ansible in the container sounds like a good solution. I guess it’s similar to what’s outlined here? https://medium.com/@tech_phil/running-ansible-inside-docker-550d3bb2bdff#.3hqqhntpk

1 Like

Exactly, this works really well.