Agentless configuration management tool.
This directory contains a development environment for Ansible Playbooks using Docker Compose. (Not intended for Ansible developing)
It defines one container with Ansible and another one with the target machine.
ansible
: Alpine with Python 2.7. Ansible is installed viagit
, the configuration inetc/
is mounted on/etc/ansible/
, and theansible/
directory is mounted on/opt/ansible
. It also contains a private key to connect to the target machinestarget
: Ubuntu Xenial with ssh server to test Ansible playbooks. Python is installed, as it's needed by Ansible to run (this would be a problem in embedded systems). It contains a public key to allow passwordless logins from Ansible container.
Just run:
docker-compose up -d
to start the target machine and the network, then run an ansible command against it:
docker-compose run ansible target -m ping
There's a key pair without passphrase to avoid password prompts. The public key is copied to target
when the image is created, but the ansible private key is mounted on the container. If want to change it, just generate another key pair and substitute the current pair.
WARNING: It uses
root
to connect, so it should't be used in production.
To discard all changes done on target
, just destroy the environment and start it again (restart
only stops and restarts the containers, so the volumes are preserved):
docker-compose down
docker-compose up -d
There are some examples in the playbooks directory. As an exercise, I'm going to write a playbook to install PostgreSQL 9.x.
The process to install PostgreSQL can be summarized as:
- Add repository
- Authenticate repository
- Install packages
- Setup configuration files
- Setup users
- Restart
These are going to be the tasks in the YML file. I've started with a simple playbook, but it's better organized as a role, so I have developed just the role.
- version: We can pass the version setting the variables in the command line:
ansible-playbook playbooks/psql.yml -e "version=9.4"
. Defaults to 9.6. - datapath: It's created based on
version
. - configpath: It's created based on
version
.
They are pretty self explanatory
- Add repo, takes in account the distro.
- Authenticate repo.
- Install packages, will use the appropiate version of
postgresql
. - Setup, uses some templating. It can be hard to be consistent between versions. Here they solved it using different templates for each version.
- Add admin user. This is tricky. Usage of
postgresql_user
module requirespsycopg2
to be installed on the target host, which is far from ideal. Other option is to create the user using a crafted query viapsql
binary, which is also crappy, so I've taken the option of installingpython-psycopg2
system package, as it's the cleanest way.
There are templates for:
- postgresql.conf
- pg_hba.conf
There are no dependecies with other roles, nor Galaxy stuff
First, we create a group in runtime to select only the Debian family, then apply the role to that group.
To ease the provision of a working desktop computer, there's a desktop.yml
playbook that will add the tools and shortcut that I usually use.
To execute this playbook in the current computer, just run:
docker-compose run ansible playbook playbooks/desktop.yml --extra-vars "host=$HOSTNAME" --user=$(whoami) --become --ask-become-pass --ask-pass
$HOSTNAME
should be in the ansible inventory (hosts in this case). You may need to add your host name and rebuild the image (docker-compose build ansible
)- docker & docker-compose should be installed (use
sudo ./bootstrap-docker-sh
) - openssh-server should be up and running
Pending:
- kops