Ansible:Ansible的SSH错误

Ansible:Ansible的SSH错误,ansible,ansible-playbook,ssh-keys,openssh,Ansible,Ansible Playbook,Ssh Keys,Openssh,我正在主机A上部署堆栈,我想在主机B上执行配置后脚本。这些脚本应该从ansible controller(主机C)或从主机A推送到主机B 为了实现这一点,我创建了一本测试剧本 - hosts: all tasks: - name: Executin python script shell: /usr/bin/python test.py # when: "'10.17.10.85' in groups['monserver']" when: "'mo

我正在主机A上部署堆栈,我想在主机B上执行配置后脚本。这些脚本应该从ansible controller(主机C)或从主机A推送到主机B

为了实现这一点,我创建了一本测试剧本

- hosts: all
  tasks:
    - name: Executin python script
      shell: /usr/bin/python test.py
#      when: "'10.17.10.85' in groups['monserver']"
      when: "'monserver' in {{ group_names }}"
      register: test
    - debug: test.stdout
我尝试了使用“when”的两种方法,并得到了相同的错误

清单文件有两个主机,都在不同的组中隔离

[controller]
10.17.10.150    ansible_ssh_user=hyroot

[monservers]
10.17.10.85     ansible_ssh_user=ubuntu
我在运行playbook时遇到了以下错误,同时我能够手动使用ssh无密码连接主机

PLAY [all] ********************************************************************

GATHERING FACTS ***************************************************************
<10.17.10.150> ESTABLISH CONNECTION FOR USER: hyroot
<10.17.10.85> ESTABLISH CONNECTION FOR USER: ubuntu
<10.17.10.150> REMOTE_MODULE setup
<10.17.10.85> REMOTE_MODULE setup
<10.17.10.150> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=hyroot', '-o', 'ConnectTimeout=10', '10.17.10.150', "/bin/sh -c 'mkdir -p /tmp/ansible-tmp-1463545052.75-6584687306251 && chmod a+rx /tmp/ansible-tmp-1463545052.75-6584687306251 && echo /tmp/ansible-tmp-1463545052.75-6584687306251'"]
<10.17.10.85> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=ubuntu', '-o', 'ConnectTimeout=10', '10.17.10.85', "/bin/sh -c 'mkdir -p /tmp/ansible-tmp-1463545052.75-48027114165698 && chmod a+rx /tmp/ansible-tmp-1463545052.75-48027114165698 && echo /tmp/ansible-tmp-1463545052.75-48027114165698'"]
<10.17.10.150> PUT /tmp/tmpfmKMrv TO /tmp/ansible-tmp-1463545052.75-6584687306251/setup
<10.17.10.150> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=hyroot', '-o', 'ConnectTimeout=10', '10.17.10.150', "/bin/sh -c 'chmod a+r /tmp/ansible-tmp-1463545052.75-6584687306251/setup'"]
<10.17.10.150> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=hyroot', '-o', 'ConnectTimeout=10', '10.17.10.150', u"/bin/sh -c 'LANG=C LC_CTYPE=C /usr/bin/python /tmp/ansible-tmp-1463545052.75-6584687306251/setup; rm -rf /tmp/ansible-tmp-1463545052.75-6584687306251/ >/dev/null 2>&1'"]
<10.17.10.85> PUT /tmp/tmpYPmXeY TO /tmp/ansible-tmp-1463545052.75-48027114165698/setup
<10.17.10.85> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=ubuntu', '-o', 'ConnectTimeout=10', '10.17.10.85', "/bin/sh -c 'chmod a+r /tmp/ansible-tmp-1463545052.75-48027114165698/setup'"]
<10.17.10.85> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=ubuntu', '-o', 'ConnectTimeout=10', '10.17.10.85', u'/bin/sh -c \'su hyroot -k && su hyroot -H -S -p "[sudo via ansible, key=tponxjlokfvzaswnynqyxdejohcambhm] password: " -u hyroot /bin/sh -c \'"\'"\'echo SUDO-SUCCESS-tponxjlokfvzaswnynqyxdejohcambhm; LANG=C LC_CTYPE=C /usr/bin/python /tmp/ansible-tmp-1463545052.75-48027114165698/setup; rm -rf /tmp/ansible-tmp-1463545052.75-48027114165698/ >/dev/null 2>&1\'"\'"\'\'']
<10.17.10.85> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=ubuntu', '-o', 'ConnectTimeout=10', '10.17.10.85', "/bin/sh -c 'rm -rf /tmp/ansible-tmp-1463545052.75-48027114165698/ >/dev/null 2>&1'"]
failed: [10.17.10.85] => {"failed": true, "parsed": false}
invalid output was: su: invalid option -- 'k'

Usage:
 su [options] [-] [USER [arg]...]

Change the effective user id and group id to that of USER.
A mere - implies -l.   If USER not given, assume root.

Options:
 -m, -p, --preserve-environment  do not reset environment variables
 -g, --group <group>             specify the primary group
 -G, --supp-group <group>        specify a supplemental group

 -, -l, --login                  make the shell a login shell
 -c, --command <command>         pass a single command to the shell with -c
 --session-command <command>     pass a single command to the shell with -c
                                 and do not create a new session
 -f, --fast                      pass -f to the shell (for csh or tcsh)
 -s, --shell <shell>             run shell if /etc/shells allows it

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see su(1).
OpenSSH_6.7p1 Debian-5, OpenSSL 1.0.1k 8 Jan 2015
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: auto-mux: Trying existing master
debug2: fd 3 setting O_NONBLOCK
debug2: mux_client_hello_exchange: master version 4
debug3: mux_client_forwards: request forwardings: 0 local, 0 remote
debug3: mux_client_request_session: entering
debug3: mux_client_request_alive: entering
debug3: mux_client_request_alive: done pid = 29670
debug3: mux_client_request_session: session request sent
debug1: mux_client_request_session: master session id: 2
debug3: mux_client_read_packet: read header failed: Broken pipe
debug2: Received exit status from master 1
Shared connection to 10.17.10.85 closed.

<10.17.10.150> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=hyroot', '-o', 'ConnectTimeout=10', '10.17.10.150', "/bin/sh -c 'rm -rf /tmp/ansible-tmp-1463545052.75-6584687306251/ >/dev/null 2>&1'"]
ok: [10.17.10.150]

TASK: [Executin python script] ************************************************
skipping: [10.17.10.150]

TASK: [debug icinga_stdout] ***************************************************
<10.17.10.150> ESTABLISH CONNECTION FOR USER: hyroot
ok: [10.17.10.150] => {
    "msg": "Hello world!"
}

PLAY RECAP ********************************************************************
           to retry, use: --limit @/root/pytask.retry

10.17.10.150               : ok=2    changed=0    unreachable=0    failed=0
10.17.10.85                : ok=0    changed=0    unreachable=0    failed=1
播放[全部]********************************************************************
收集事实***************************************************************
为用户建立连接:hyroot
为用户建立连接:ubuntu
远程模块设置
远程模块设置
执行官['ssh'、'-C'、'-tt'、'-vvv'、'-o'、'ControlMaster=auto'、'-o'、'ControlPersist=60s'、'-o'、'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r'、'-o'、'kbdinteractivateAuthentication=no'、'-o'、'PreferredAuthentications=gssapi with-mic、gssapi-keyex、基于主机、公钥'、'o'、'PasswordAuthentication=no'、'o'、'User=hyroot'、'o'、'ConnectTimeout=10“,'10.17.10.150',”/bin/sh-c'mkdir-p/tmp/ansible-tmp-1463545052.75-6584687306251和&chmod a+rx/tmp/ansible-tmp-1463545052.75-6584687306251和&echo/tmp/ansible-tmp-14635445052.75-6584687306251'”
执行官['ssh'、'-C'、'-tt'、'-vvv'、'-o'、'ControlMaster=auto'、'-o'、'ControlPersist=60s'、'-o'、'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r'、'-o'、'KbdInteractiveAuthentication=no'、'-o'、'PreferredAuthentications=gssapi-with-mic、gssapi-keyex、基于主机的公钥'、'o'、'PasswordAuthentication=no'、'o'、'o'、'User=ubuntu'、'o'、'ConnectTimeout=10“,'10.17.10.85',”/bin/sh-c'mkdir-p/tmp/ansible-tmp-1463545052.75-48027114165698和&chmod a+rx/tmp/ansible-tmp-1463545052.75-48027114165698和&echo/tmp/ansible-tmp-1463545052.75-48027114165698']
将/tmp/tmpfmKMrv置于/tmp/ansible-tmp-1463545052.75-6584687306251/setup
执行官['ssh'、'-C'、'-tt'、'-vvv'、'-o'、'ControlMaster=auto'、'-o'、'ControlPersist=60s'、'-o'、'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r'、'-o'、'kbdinteractivateAuthentication=no'、'-o'、'PreferredAuthentications=gssapi with-mic、gssapi-keyex、基于主机、公钥'、'o'、'PasswordAuthentication=no'、'o'、'User=hyroot'、'o'、'ConnectTimeout=10“,'10.17.10.150',”/bin/sh-c'chmod a+r/tmp/ansible-tmp-1463545052.75-6584687306251/setup']
执行官['ssh'、'-C'、'-tt'、'-vvv'、'-o'、'ControlMaster=auto'、'-o'、'ControlPersist=60s'、'-o'、'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r'、'-o'、'kbdinteractivateAuthentication=no'、'-o'、'PreferredAuthentications=gssapi with-mic、gssapi-keyex、基于主机、公钥'、'o'、'PasswordAuthentication=no'、'o'、'User=hyroot'、'o'、'ConnectTimeout=10“,'10.17.10.150',u”/bin/sh-c'LANG=c LC_CTYPE=c/usr/bin/python/tmp/ansible-tmp-1463545052.75-6584687306251/setup;rm-rf/tmp/ansible-tmp-146354545052.75-6584687306251/>/dev/null 2>&1']
将/tmp/tmpYPmXeY放到/tmp/ansible-tmp-1463545052.75-48027114165698/setup
执行官['ssh'、'-C'、'-tt'、'-vvv'、'-o'、'ControlMaster=auto'、'-o'、'ControlPersist=60s'、'-o'、'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r'、'-o'、'KbdInteractiveAuthentication=no'、'-o'、'PreferredAuthentications=gssapi-with-mic、gssapi-keyex、基于主机的公钥'、'o'、'PasswordAuthentication=no'、'o'、'o'、'User=ubuntu'、'o'、'ConnectTimeout=10“,'10.17.10.85',”/bin/sh-c'chmod a+r/tmp/ansible-tmp-1463545052.75-48027114165698/setup']
执行官['ssh'、'-C'、'-tt'、'-vvv'、'-o'、'ControlMaster=auto'、'-o'、'ControlPersist=60s'、'-o'、'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r'、'-o'、'KbdInteractiveAuthentication=no'、'-o'、'PreferredAuthentications=gssapi-with-mic、gssapi-keyex、基于主机的公钥'、'o'、'PasswordAuthentication=no'、'o'、'o'、'User=ubuntu'、'o'、'ConnectTimeout=10“,'10.17.10.85',u'/bin/sh-c \-su-hyroot-k和&su-hyroot-H-S-p”[sudo-via-ansible,key=tponxjlokfvzaswnyxdejohcambhm]密码:“-u-hyroot/bin/sh-c\”\“echo SUDO SUDO SUCCESS tponxjlokfvzaswnyxyxdejohcambhm;LANG=C LC_CTYPE=C/usr/bin/python/tmp/ansible-tmp-1463545052.75-48027114165698/setup;rm-rf/tmp/ansible-tmp-146354545052.75-48027114165698/>/dev/null 2>&1\'''''''''''''''\'''']
执行官['ssh'、'-C'、'-tt'、'-vvv'、'-o'、'ControlMaster=auto'、'-o'、'ControlPersist=60s'、'-o'、'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r'、'-o'、'KbdInteractiveAuthentication=no'、'-o'、'PreferredAuthentications=gssapi-with-mic、gssapi-keyex、基于主机的公钥'、'o'、'PasswordAuthentication=no'、'o'、'o'、'User=ubuntu'、'o'、'ConnectTimeout=10“,'10.17.10.85',”/bin/sh-c'rm-rf/tmp/ansible-tmp-1463545052.75-48027114165698/>/dev/null 2>&1']
失败:[10.17.10.85]=>{“失败”:true,“已解析”:false}
无效输出为:su:无效选项--“k”
用法:
su[选项][-][用户[arg]…]
将有效用户id和组id更改为用户id和组id。
一个简单的-意味着-l。如果用户没有给出,则假定为root。
选项:
-m、 -p,--preserve environment不重置环境变量
-g、 --组指定主组
-G、 --补充组指定补充组
-,-l,--login使shell成为登录shell
-c、 --command使用-c将单个命令传递给shell
--session命令使用-c将单个命令传递给shell
并且不创建新会话
-f、 --快速传递-f至外壳(用于csh或tcsh)
-s、 --如果/etc/shell允许,shell将运行shell
-h、 --帮助显示此帮助并退出
-五、 --版本输出版本信息并退出
有关更多详细信息,请参见su(1)。
OpenSSH_6.7p1 Debian-5,OpenSSL 1.0.1k 2015年1月8日
debug1:读取配置数据/etc/ssh/ssh\u config
debug1:/etc/ssh/ssh\u配置第19行:应用*
debug1:自动多路复用器:尝试现有主机
调试2:fd 3设置O_非块
debug2:mux\u客户端\u你好\u交换:主版本