微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

带有 ssh 密钥的 Ansible Ad-Hoc 命令

如何解决带有 ssh 密钥的 Ansible Ad-Hoc 命令

我想在我的 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

知道这里有什么问题吗?非常感谢

解决方法

乍一看,当 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"
    },"ping": "pong"
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?