Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify docker containers in /etc/ansible/hosts file

Tags:

docker

ansible

I have a bunch or docker containers running on my local machine and would like to test ansible on those - acting as my remote hosts.

But I have not been able to find any guides for this. For now I am trying to configure a single container to have SSH enabled using: https://docs.docker.com/engine/examples/running_ssh_service/

but I am struggling with getting that to work. Currently I have

localhost:32768

in /etc/ansible/hosts but it seems it just runs my ansible tasks on my host and not on my running container.

So is it even possible to test ansible on a bunch of docker containers on the same machine?

like image 510
u123 Avatar asked Oct 21 '25 00:10

u123


1 Answers

For local docker connection you can use docker connection plugin.

hosts:

[cont]
container-name1
container-name2
[cont:vars]
ansible_connection=docker

playbook:

- hosts: cont
  tasks:
    - command: "echo 'hello, container'"
like image 176
Konstantin Suvorov Avatar answered Oct 23 '25 20:10

Konstantin Suvorov