【问题标题】:how to use passwords with @ ! # chars in ansible shell ssh?如何在 @ 中使用密码! # ansible shell ssh 中的字符?
【发布时间】:2020-10-12 15:23:39
【问题描述】:

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

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

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. 单/双引号

我没有想法。

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

信息:

  • ansible 2.9.6
  • python version = 3.8.2 (default, Jul 16 2020, 14:00:26) [GCC 9.3.0]
  • 从 Ubuntu 连接到 RHEL 机器
  • 使用没有此类“特殊”字符的密码与另一个 RHEL 框类似的连接工作正常
  • 我无法定义公钥/私钥或更改密码。目标盒子由另一个团队安装和配置,然后在多个其他团队之间共享。

【问题讨论】:

  • 它适用于 Ubuntu 20.4 和 FreeBSD 12.0(无 RH atm)。不需要转义/引用“ansible_ssh_pass: mY*test@2PAss!01lZ#”。确保问题不是sshpass。试试“ansible_connection: paramiko”。
  • FWIW,在 Ansible 的 sshpass 使用中存在一些奇怪的密码缓存。库存中更改的密码不会立即生效。
  • 尝试使用paramiko,得到:SRV1 | UNREACHABLE! => { "changed": false, "msg": "Failed to authenticate: Authentication failed.", "unreachable": true }
  • 顺便说一句,我已经尝试了几次直接 ssh 到节点,并从清单文件中复制粘贴密码,并且它有效。
  • 天哪,其实这很傻。我打错了主机 IP 的最后一个数字 :) 谢谢大家的帮助。

标签: shell ssh ansible


【解决方案1】:

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

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

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

所以这不是一般问题。

【讨论】:

    猜你喜欢
    • 2021-03-21
    • 2014-04-18
    • 2019-01-13
    • 1970-01-01
    • 2020-06-30
    • 2011-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多