首页 > 解决方案 > 如何在 @ 中使用密码!# ansible shell ssh 中的字符?

问题描述

我正在尝试通过 SSH 在一堆远程服务器上运行一些简单的检查。没有什么花哨。其中一台服务器的密码类似于mY*test@2PAss!01lZ#我的库存.yml文件。

对于这个特定的服务器,我得到:

SRV1 | UNREACHABLE! => {
    "changed": false,
    "msg": "Invalid/incorrect password: Failed to add the host to the list of known hosts (/home/redacted/.ssh/known_hosts).\r\n------------------------------------------------------------------------------\n* WARNING                                                                    *\n* You are accessing a secured system and your actions will be logged along   *\n* with identifying information. Disconnect immediately if you are not an     *\n* authorized user of this system.                                            *\n------------------------------------------------------------------------------\nPermission denied, please try again.",
    "unreachable": true
}

我尝试过的所有事情都不起作用:

  1. 转义或, , ,字符mY*test\@2PAss\!01lZ\#的任何其他组合*@!#
  2. 使用 ansible 保险库
  3. 使用ansible_ssh_pass: "{{ i_pass | regex_escape() }}"
  4. 单/双引号

我没主意了。

有人遇到过类似的问题吗?

信息:

标签: shellsshansible

解决方案


使用公钥认证更容易,因此您不需要任何密码。

关于特殊字符,我做了一个测试:

ansible localhost -m command -a "echo '{{ a }}'" -e '{"a": "mY*test@2PAss!01lZ#"}'
localhost | CHANGED | rc=0 >>
mY*test@2PAss!01lZ#

所以这不是一般问题。


推荐阅读