Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Set up your own Ansible Lab using Docker
Rohit Kalyan Kandulapati
Rohit Kalyan Kandulapati

Posted on

     

Set up your own Ansible Lab using Docker

Hi there 👋
This is Rohit and this is my first post on Dev.to

I know finding the right infra for learning Ansible is hard but not impossible. Today we are going to setup our own ansible lab in our system, which don't have any restrictions and any time limits.

Prerequisites: Docker in your system, Interest in you to learn Ansible.

Steps to setup Ansible lab:

1. Pulling the image

Pull the ubuntu image
docker pull ubuntu

Docker Images

2. Setting Up docker network

Create a docker network with a specific subnet
docker network create ansible-network --subnet 192.168.1.0/24

3. Setting up Ansible Master Container

a. Run the ubuntu image.
docker run -d -it --name ansible-master --net ansible-network --hostname ans_master ubuntu

b. Login into the container
docker exec -it ansible-master /bin/bash

c. Run the below commands

# 1apt update# 2aptinstallvim python-is-python3 openssh-client iputils-ping ansible-y# 3ssh-keygen# you will be prompted for responses, just keep clicking enter.
Enter fullscreen modeExit fullscreen mode

4. Setting up Manage Container-1

You can use the below setup to add as many managed nodes as you want, you just need to change the container name.

a. Run the ubuntu image
docker run -d -it --name ansible-manage-1 --net ansible-network --ip 192.168.1.18 --hostname ans_master ubuntu

b. Login in to the container
docker exec -it ansible-manage-1 /bin/bash

c. Run the below commands

# 1apt update# 2aptinstallvim python-is-python3 openssh-client openssh-server-y# 3apt update# 4service ssh start
Enter fullscreen modeExit fullscreen mode

5. Password-less authentication

a. Copy the contents of.pub file under the path~/.ssh/ on your control container.
b. Add that to~/.ssh/authorized_keys in your managed containers. Create the file if that file is not present and you should do the same for all your managed containers.
c. Try running the below command in your control container.
ssh root@ans_manage
Enter yes.

Now you have successfully setup password-less authentication from your control container to managed container.

6. Validate using ping module

a. Create andinventory.ini file in your control node under/home/ubuntu and add the below contents. (Make sure you have exited from the ssh connection)

192.168.1.18 ansible_user=root
Enter fullscreen modeExit fullscreen mode

b. Run the below command
ansible -i /home/ubuntu/inventory.ini -m ping all
Just enter for one more time(last time).

Ping

Happy Learning 🎉🎉

Let us know in the comments if you find any difficulties.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Joined

More fromRohit Kalyan Kandulapati

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp