TransWikia.com

How to test Ansible after deploy & run it in DockerDesktop on Windows-10

Stack Overflow Asked on November 20, 2021

My windows-10 has Docker Desktop installed.
I have deployed Ansible image on the Docker by using following command from Dos command prompt :

C:docker pull ansible/ansible:ubuntu1404

And then run using below command :

C:docker run ansible/ansible:ubuntu1404

It is showing that Ansible is up and running in the DockerDesktop Dashboard

Now I wanted to perform following very simple tasks to check whether Ansible is working or not:

  1. Check the version of the Ansible
  2. Ping localhost using ansible-playbook
  3. Change the inventory file by adding another host
  4. ping the new host

I tried using some commands from Ansible container bash terminal, but none of them work.

I also tried using docker run command from my Dos prompt like below, but that did not work too:

c:docker run --rm -it -v /ansible/playbooks     ansible/ansible-playbook --version

Please suggest how I can test the above simple tasks to start with.

2 Answers

Conclusion : When you want to create Docker container as your Ansible Control node, you need following simple step to perform:

  1. Create a Dockerfile with your desired OS (e.g., Ubuntu, Fedora, CentOS) along with Ansible
  2. Build your Docker image with your desired name by using the Dockerfile you created
  3. Run the docker image you created. (Note : You should have your DockerDesktop in running state)
  4. Start your container with a Bash
  5. In your Bash terminal you execute your Ansible Commands

Answered by SKC on November 20, 2021

I had a look at the Docker-Image ansible/ansible:ubuntu1404.

  • It's a very old image (currently we have Ubuntu 20.04)
  • It has no Ansible installed [1]

If you're not able to install Ansible on your workstation, i would recommend you to create your own container with a Ubuntu 20.04 as Base. [2]

Then, you should be able to start your container with a Bash and run the Ansible commands.

Edit: To be more clear, here an example to start with:

Since there is no Docker-Image (which i know) which already has Ansible installed, you could create your own:

Dockerfile:

FROM ubuntu:latest

RUN apt-get update && apt-get install -y ansible 
  && rm -rf /var/lib/apt/lists/*

In the directory, where you created the Dockerfile you can execute the docker build: docker build . -t myansible:v01 This will create a Docker-Image with the latest Ubuntu and install Ansible. The Image-Name will be myansible with the tag v01.

After you build your image, you can run it and play with the Ansible command:

#docker run --rm -it myansible:v01 /bin/bash

root@eee0671466ca:/# ansible --version
ansible 2.9.6
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.8.2 (default, Jul 16 2020, 14:00:26) [GCC 9.3.0]

root@eee0671466ca:/# ansible localhost -m ping
localhost | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

[1] https://hub.docker.com/r/ansible/ansible/dockerfile

[2] https://docs.docker.com/get-started/part2/

Answered by CLNRMN on November 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP