Giter Club home page Giter Club logo

ansible-docker's Introduction

ansible-docker

Preparations

Create a pair of SSH keys

Generate id_rsa.pub and ir_rsa keys (no password):

ssh-keygen -t rsa

Copy the previously generated keys to the ansible-docker/config/.ssh folder.

Build image

cd deploy
docker build . -t fredrikaverpil/ansible:1.0

Please note that the previously created keys are added to the image during the build.

Run container

This will run the container and enter it, allowing for interactively working with ansible.

cd deploy
docker run --rm --interactive --tty --volume ${PWD}/../config/ansible/ansible.cfg:/etc/ansible/ansible.cfg --volume ${PWD}/../config/ansible/hosts:/etc/ansible/hosts --volume ${PWD}/../config/ansible:/ansible fredrikaverpil/ansible:1.0

Container commands

The following applies only to when running interactively inside the container.

Deploy SSH keys onto clients

You can copy the id_rsa.pub over to machines using ssh-copy-id:

ssh-copy-id -i ~/.ssh/id_rsa user@host

This logs into the server host, and copies keys to the server, and configures them to grant access by adding them to the authorized_keys file. The copying may ask for a password or other authentication for the server. Only the public key is copied to the server. The private key should never be copied to another machine.

This all will ensure that our control machine can get SSH access to the remote machine(s).

If you have many machines to copy the key to, this may help, use the /ansible/tools/deploy_keys.sh.

If the SSH keys doesn't seem to work, try this:

ssh-agent bash
ssh-add ~/.ssh/id_rsa

Add hosts

Add machines to the inventory; /etc/ansible/hosts, example:

[farm]
192.168.0.101
192.168.0.102
192.168.0.103

Test it out from the ansible control machine:

ansible all -m ping
ansible all -a "/bin/echo hello"

Using specified usernames/passwords for SSH connections (no ssh-agent)

Instead of using the deployed keys, user and password can be specified directly in the inventory hosts file (not recommended!).

In the /etc/ansible/hosts, specify e.g:

[farm:vars]
ansible_user=vagrant
ansible_pass=vagrant
ansible_connection=ssh

Run playbook examples

# Linux
ansible-playbook /ansible/playbooks/helloworld.yml

Windows support

Windows:

Stop and remove container, image

docker stop ansible
docker rm -v ansible
docker rmi fredrikaverpil/ansible:1.0

ansible-docker's People

Contributors

fredrikaverpil avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.