Skip to content

The project can immediately create a docker container as Ansible control node to run Ansible playbook.

License

Notifications You must be signed in to change notification settings

KarateJB/Ansible.ControlNode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ansible.ControlNode

The project can immediately create a docker container as Ansible control node to run Ansible playbook.

Github

Docker Hub

See HOW TO USE and following the steps.


HOW TO USE

1. PULL DOCKER IMAGE

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

2. Run the container

$ 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

3. Set SSH public key to Managed node

The container had already generated a new SSH public & private keys in ~/.ssh/.

├── id_rsa
├── id_rsa.pub
└── known_hosts

3.1 Get the SSH public key

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/

3.2 Write back to Managed node

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

APPENDIX

Build Dockerfile

$ docker build --no-cache  -t ansible-control-node:ubuntu1804 .

Push to Docker Hub

$ docker login
$ docker tag ansible-control-node:ubuntu1804 karatejb/ansible-control-node:ubuntu1804
$ docker push karatejb/ansible-control-node:ubuntu1804

Run the Test playbook

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

About

The project can immediately create a docker container as Ansible control node to run Ansible playbook.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published