Saturday, December 16, 2017

Getting started with Ansible in Docker

Since OpenShift uses Ansible, and also since I hate Puppet, I love Python, Ansible is based on Python and I always wanted to learn a Provisioning tool other from Puppet to prove that Puppet folks are losers...
and since Ansible can nuke your environment if used incorrectly....

I am installing Ansible in a docker Centos machine, so I can nuke it at my will!

docker pull centos
#here nothing happens
docker run centos
docker container ls
docker run -i -t centos
yum install man
yum install ansible
#note down the container id, it's displayed after the root@ prompt , like in root@61d50a06c86c
docker commit 61d50a06c86c centosansible

at this point I can easily run:
docker run -i -t centosansible

and if I do
docker images | grep centos
centosansible latest 2766690643c3 9 minutes ago 353MB
centos latest 3fa822599e10 2 weeks ago 204MB

I see that my image is there (the 353MB size include all the layers from centos image, which are NOT duplicated, so the real additional space is only 353-204=149 MB

ansible --version
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Aug  4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]

ansible localhost -a /bin/date

ansible localhost -m ping

This is a nice tutorial - skip first 13 minutes, then you have 20 minutes of theory, then some interesting Ansible examples

No comments: