在/etc/ansible/hosts 文件中指定 docker 容器 [英] Specify docker containers in /etc/ansible/hosts file

查看:44
本文介绍了在/etc/ansible/hosts 文件中指定 docker 容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆或 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.

但是我找不到任何有关此的指南.现在,我正在尝试配置单个容器以使用以下方法启用 SSH:https://docs.docker.com/engine/examples/running_ssh_service/

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

/etc/ansible/hosts 中,但它似乎只是在我的主机上运行我的 ansible 任务,而不是在我正在运行的容器上.

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

那么是否有可能在同一台机器上的一堆 docker 容器上测试 ansible?

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

推荐答案

对于本地 docker 连接,您可以使用 docker 连接插件.

For local docker connection you can use docker connection plugin.

主机:

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

剧本:

- hosts: cont
  tasks:
    - command: "echo 'hello, container'"

这篇关于在/etc/ansible/hosts 文件中指定 docker 容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆