The project can immediately create a docker container as Ansible control node to run Ansible playbook.
See HOW TO USE and following the steps.
$ docker pull karatejb/ansible-control-node:latestFor more tags, see karatejb/ansible-control-node.
Before using the container to run your Ansible playbook, you have to
- Prepare your Ansible playbook.
- Set the SSH key on Managed node.
$ docker run -d -it [-v /Demo/Playbooks:/dev/ansible:rw] --name <container_name> karatejb/ansible-control-node:ubuntu1804 bashUse volume to mounts the playbooks on your docker host into the container in order to run the playbook, it is optional.
For example,
$ docker run -d -it -v /Demo/Playbooks:/dev/ansible:rw --name my-ansible karatejb/ansible-control-node:ubuntu1804 bashFor Docker for Windows, run as following,
$ docker run -d -it -v D:\...:/dev/ansible --name ansible-control karatejb/ansible-control-node:ubuntu1804 bashThe container had already generated a new SSH public & private keys in ~/.ssh/.
├── id_rsa
├── id_rsa.pub
└── known_hosts
On docker host, copy the SSH pulic key from Control node, and copy the authorized_keys from Managed node.
- Copy the SSH public key from the Ansible container
$ mkdir tmp
$ docker cp my-ansible:/root/.ssh/id_rsa.pub ./tmp/Copy the authorized_keys from Managed node
$ scp [-P 22] root@<managed_node_ip>:~/.ssh/authorized_keys ./tmp/Update authorized_keys with the SSH public key
$ cat tmp/id_rsa.pub >> tmp/authorized_keysCopy back the updated authorized_keys to Managed node
$ scp [-P 22] tmp/authorized_keys root@<managed_node_ip>:~/.ssh/authorized_keys$ docker build --no-cache -t ansible-control-node:ubuntu1804 .$ docker login
$ docker tag ansible-control-node:ubuntu1804 karatejb/ansible-control-node:ubuntu1804
$ docker push karatejb/ansible-control-node:ubuntu1804First update the Managed Node's information in Demo/Playbooks/Test/inventory.
Assume that the mounted path in container is /dev/ansible
$ cd /dev/ansible/Test
$ ansible-playbook --private-key ~/.ssh/id_rsa -i inventory playbook.ymlOr run it with ansible.cfg,
$ ansible-playbook playbook.yml