docker - ansible over docker hosts 不如预期
问题描述
我在 ansible docker 容器中遇到了一些奇怪的问题。存货
el7_02 ansible_port=6000 ansible_user=user ansible_host=localhost
el7_03 ansible_port=6001 ansible_user=user ansible_host=localhost
剧本
- shell: hostname
register: x
- debug: msg="{{ x.stdout}}, {{ansible_hostname}}, {{ansible_user}}, {{ansible_port}}"
输出
TASK [Gathering Facts] *************************************************************************************************
ok: [el7_03]
ok: [el7_02]
TASK [x : shell] *************************************************************************************************
changed: [el7_03]
changed: [el7_02]
TASK [x : debug] *************************************************************************************************
ok: [el7_03] => {
"msg": "el7_02, el7_02, user, 6001"
}
ok: [el7_02] => {
"msg": "el7_02, el7_02, user, 6000"
}
正如您所看到的,由于某些原因,我没有看到容器 el7_03 的预期主机名。虽然我希望在 docker el7_03 的调试任务中看到相同的主机名(即 el7_03 但不是 el7_02)。为什么我收到“错误”的输出?
检查 docker 中的主机名
~/ $ ssh -p 6000 user@localhost 'hostname'
el7_02
~/ $ ssh -p 6001 user@localhost 'hostname'
el7_03
如果我会切换到,ansible_connection=docker
那么我会得到我所期望的。但是,我不能使用它,因为当我与笔记本电脑外部的任何东西(安装任何东西或从互联网下载)交互时(而且经常)我会收到超时。也许有办法摆脱超时?
操作系统:macos ansible:2.9.11 python:3.8.5 docker:19.0.3.8
谢谢你
解决方案
您需要解决 ansible 通过 hostname 而不是通过 hostname:port pair 查找主机的问题。
我对这个问题的解决方法如下:
$ grep pi. /etc/hosts
127.0.0.1 pi1
127.0.0.1 pi2
127.0.0.1 pi3
# inventory contents:
$ cat all_rpis.ini
pi1:3321
pi2:3322
pi3:3323
推荐阅读
- java - SSLHandshakeException 与 jlink 创建运行时
- c - 即使 IF 语句为假,字符指针数组也会被覆盖
- javascript - Javascript井字游戏:如何提醒用户他赢了?
- c++ - 获取 __m256 变量中不为零的第一个元素的索引
- vb.net - 如果通过代理作业或 TSQL 运行,脚本任务中带有 SSRS 报告的 SSIS 包将不起作用
- django - 当表单中还存在其他字段时,获取图像的 content_type 的问题
- c++ - 如何降低这段代码的复杂度
- amazon-s3 - 使用 Amazon SES、Lambda 和 S3 跟踪内部和外部电子邮件的打开和点击?
- angular - 如何在 Angular 7 中等待 DOM 更改就绪?
- angular - 如何使用 Angular 在 Stackblitz 中导入 Lodash?