【问题标题】:Ansible fails to construct desired ssh commandAnsible 无法构造所需的 ssh 命令
【发布时间】:2018-12-07 21:06:26
【问题描述】:

我的组织制定了一项政策,允许“仅”以下 ssh 命令工作。

ssh -i /tmp/private.key -t user2@host2 bash --noprofile

我尝试修改ansibleinventory主机文件来构造上面的ssh。请参阅下面的我的 ansible 主机文件:

host2 ansible_ssh_common_args="-t -o UserKnownHostsFile=/dev/null" ansible_shell_executable=sh ANSIBLE_HOST_KEY_CHECKING=false ansible_ssh_private_key_file=/tmp/private.key  USER_RUN=user2

我也尝试了以下方法,但它们也失败了

ansible_shell_executable=/bin/bash
ansible_ssh_extra_arg=.....

我的 ansible 版本是:

ansible --version

ansible 2.7.1

  config file = /etc/ansible/ansible.cfg

  configured module search path = [u'/home/user1/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']

  ansible python module location = /usr/lib/python2.7/site-packages/ansible

  executable location = /bin/ansible

  python version = 2.7.5 (default, Sep 12 2018, 05:31:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

在调试中我看到ansible构造的ssh没有

bash --noprfile

在 user2@target2 之后

请帮助提供解决方案。

【问题讨论】:

    标签: ssh ansible


    【解决方案1】:

    为此,您可以通过

    为特定主机设置远程shell

    库存

    some_host  ansible_shell_executable="/bin/bash --noprofile"
    other_host ansible_shell_executable="/bin/bash --noprofile"
    

    或全局通过

    ansible.cfg

    executable = /bin/bash --noprofile
    

    更多信息可以在ansibledocumentation找到。

    请注意,ansible 还会在后台进行 sftp 传输。

    恕我直言,如果您想在您的组织中使用 ansible,更改政策是合理的。

    【讨论】:

    • 如果我们暂时离开/忽略 --noprofile 我们可以在 user2@host2 之后只构建 bash 吗?请告诉我怎么做?
    • 更正了我的答案
    • 如果您查看我已经提到 ansible_shell_executable=/bin/bash not working 的原始帖子,我希望您的建议是什么?如果我错了,请纠正我?
    • 是的,试试我的第二个解决方案,通过ansible.cfg 进行全局设置。
    • 我无法编辑/影响全局配置,因为我的 ansible 连接到不需要我们尝试填充的 ssh 命令的其他服务器。如果我们能找到仅适用于我本地剧本的修复程序,那就太好了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多