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:latest
For 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 bash
Use 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 bash
For Docker for Windows, run as following,
$ docker run -d -it -v D:\...:/dev/ansible --name ansible-control karatejb/ansible-control-node:ubuntu1804 bash
The 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_keys
Copy 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:ubuntu1804
First 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.yml
Or run it with ansible.cfg
,
$ ansible-playbook playbook.yml