u123
u123

Reputation: 16267

Specify docker containers in /etc/ansible/hosts file

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?

Upvotes: 4

Views: 4200

Answers (1)

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68239

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'"

Upvotes: 4

Related Questions