GithubHelp home page GithubHelp logo

ansible-centos's Introduction

Quick start

Clone repository

Clone this git repository:

git clone https://github.com/sangeetprasad/ansible-centos.git

Build images and run containers

Enter ansible directory containing docker-compose.yml file.

Build docker images and run containers in the background (details defined in docker-compose.yml):

docker-compose up -d --build

Connect to master node:

docker exec -it master01 bash

Verify if network connection is working between master and managed hosts:

ping -c 2 host01

Start an SSH Agent on master node to handle SSH keys protected by passphrase:

ssh-agent bash

Load private key into SSH Agent in order to allow establishing connections without entering key passphrase every time:

ssh-add master_key

Enter passphrase for master_key:

As passphrase enter: 12345

Default key passphrase can be changed in ansible/master/Dockerfile

Ansible playbooks

Run a sample ansible playbook that checks connection between master node and managed hosts:

ansible-playbook -i inventory ping_all.yml

Confirm every new host for SSH connections:

ECDSA key fingerprint is SHA256:HwEUUnBtOm9hVAR2PJflNdCVchSCzIlpOpqYlwp+w+w.
Are you sure you want to continue connecting (yes/no)?

Type: yes (three times)

Install PHP on web inventory group:

In order to group managed hosts for easier maintenance you can use groups in ansible inventory file.

Run a sample ansible playbook:

ansible-playbook -i inventory install_php.yml

Copy data between local file system and containers

Copy directory from container to local file system

docker cp master01:/var/ans/ .

Copy directory from local file system to container:

docker cp ./ans master01:/var/

You can check usage executing:

docker cp --help

Cleanup

After you are done with your experiments or want to destroy lab environment to bring new one execute following commands.

Stop containers:

docker-compose kill

Remove containers:

docker-compose rm

Remove volume:

docker volume rm ansible_ansible_vol

If you want you can remove Docker images (although that is not required to start new lab environment):

docker rmi ansible_host ansible_master ansible_base

Tips

In order to share public SSH key between master and host containers I used Docker volume mounted to all containers:

docker-compose.yml:

[...]
volumes:
  - ansible_vol:/var/ans
[...]

Master container stores SSH key in that volume (ansible/master/Dockerfile):

[...]
WORKDIR /var/ans
RUN ssh-keygen -t rsa -C "master key" -f master_key
[...]

And host containers add SSH public key to authorized_keys file (ansible/host/run.sh) in order to allow connections from master:

cat /var/ans/master_key.pub >> /root/.ssh/authorized_keys

IMPORTANT: this is valid setup for lab environment but for production deployment you have to distribute the public key other way.

Troubleshooting

Host containers stop after creation

Check that ansible/hosts/run.sh has proper end of line type - it should be Linux/Unix (LF) not Windows (CRLF). You can change end of line type using source code editor (like Notepad++ or Visual Studio Code); under Linux you can use dos2unix command.

Other issue

Please open an issue and I'll try to help.

ansible-centos's People

Contributors

sangeetprasad avatar

Watchers

 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.