0

我想在我的 Mac 上设置 ansible。我在 GNS3 中做过类似的事情,它确实有效,但这里还有更多我需要考虑的因素。所以我安装了 Ansible。我在 /etc/hosts 中添加了主机名,我可以使用我在那里提供的主机名 ping。

我创建了我要使用的 ansible 文件夹并将 ansible.cfg 放入其中:

[defaults]
hostfile = ./hosts
host_key_checking = false
timeout = 5
inventory = ./hosts

在同一个文件夹中,我有主机文件:

[tp-lab]
lab-acc0

当我尝试运行以下命令时: ansible tx-edge-acc0 -m ping

我收到以下错误:

[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
[WARNING]: Unhandled error in Python interpreter discovery for host tx-edge-acc0: unexpected output from Python interpreter discovery
[WARNING]: sftp transfer mechanism failed on [tx-edge-acc0]. Use ANSIBLE_DEBUG=1 to see detailed information
[WARNING]: scp transfer mechanism failed on [tx-edge-acc0]. Use ANSIBLE_DEBUG=1 to see detailed information
[WARNING]: Platform unknown on host tx-edge-acc0 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change the meaning of that path. See
https://docs.ansible.com/ansible/2.10/reference_appendices/interpreter_discovery.html for more information.
tx-edge-acc0 | FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "module_stderr": "Shared connection to tx-edge-acc0 closed.\r\n",
    "module_stdout": "\r\nerror: unknown command: /bin/sh\r\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 0

知道这里可能有什么问题吗?非常感激

4

1 回答 1

0

乍一看,当 playbook 被触发时,您的 ansible 控制器似乎没有加载配置文件(尤其是 ansible.cfg)。

来自文档) Ansible 按以下顺序搜索配置文件,处理它找到的第一个文件并忽略其余文件:

  1. $ANSIBLE_CONFIG如果设置了环境变量。
  2. ansible.cfg如果它在当前目录中。
  3. ~/.ansible.cfg如果它在用户的主目录中。
  4. /etc/ansible/ansible.cfg,默认配置文件。

编辑:为了安心,最好使用完整路径

编辑基于评论

$ cat /home/ansible/ansible.cfg
[defaults]
host_key_checking = False
inventory = /home/ansible/hosts  # <-- use full path to inventory file

$ cat /home/ansible/hosts
[servers]
server-a
server-b

命令和输出:

# Supplying inventory host group! 
$ ansible servers -m ping
server-a | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
server-b | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
于 2021-03-04T14:12:41.203 回答