【发布时间】:2022-05-21 07:36:21
【问题描述】:
我是 ansible 的新手,我正在尝试在一些 lxc 容器上使用 ansible。 我的问题是我不想在我的容器上安装 ssh。所以
我尝试了什么:
我尝试使用此连接plugin,但似乎它不适用于 ansible 2。
在了解了chifflier连接插件不起作用后,我尝试使用openstack的连接插件。
在一些失败的尝试之后,我深入研究了代码,我明白了 该插件没有我正在与之交谈的主机是容器的信息。(因为代码从未到达此point)
我目前的设置: {Ansbile 主机}---|ssh|---{vm}--|ansible 连接插件|---{container1}
我的 ansible.cfg:
[defaults]
connection_plugins = /home/jkarr/ansible-test/connection_plugins/ssh
inventory = inventory
我的库存:
[hosts]
vm ansible_host=192.168.28.12
[containers]
mailserver physical_host=vm container_name=mailserver
我的组变量:
ansible_host: "{{ physical_hostname }}"
ansible_ssh_extra_args: "{{ container_name }}"
ansible_user: containeruser
container_name: "{{ inventory_hostname }}"
physical_hostname: "{{ hostvars[physical_host]['ansible_host'] }}"
我的测试手册:
- name: Test Playbook
hosts: containers
gather_facts: true
tasks:
- name: testfile
copy:
content: "Test"
dest: /tmp/test
输出是:
fatal: [mailserver]: UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname mailserver: No address associated with hostname\r\n",
"unreachable": true
}
Ansible 版本为:2.3.1.0
那我做错了什么?有小费吗? 提前致谢!
更新 1:
基于eric answer,我现在正在使用此连接plug-in。
我更新了我的库存,它看起来像:
[hosts]
vm ansible_host=192.168.28.12
[containers]
mailserver physical_host=vm ansible_connection=lxc
运行我的剧本后,我采取了:
<192.168.28.12> THIS IS A LOCAL LXC DIR
fatal: [mailserver]: FAILED! => {
"failed": true,
"msg": "192.168.28.12 is not running"
}
这很奇怪,因为 192.168.28.12 是虚拟机,而容器称为邮件服务器。我还验证了容器正在运行。
还有为什么它说 192.168.28.12 是本地 lxc 目录?
更新 2:
我从 playbook 中删除了我的 group_vars、我的 ansible.cfg 和连接插件,我得到了这个错误:
<mailserver> THIS IS A LOCAL LXC DIR
fatal: [mailserver]: FAILED! => {
"failed": true,
"msg": "mailserver is not running"
}
【问题讨论】:
-
该错误表示主机邮件服务器未在 Ansible 清单文件中分配 IP。可以给主机设置IP再试一下吗?
-
@Tejaswi 我试图将'mailserver'更改为容器的分配IP,但我得到了同样的错误。
-
@jkarr 你的
group_vars覆盖ansible_host。你能试试没有group_vars的简单debug吗? -
@EricCitaire 在删除 group_vars、connection_plugin 文件夹和 ansible.cfg 后,我得到了类似的错误,请参阅更新的问题。
-
你试过加
container_name=mailserver吗?