Ansible:ansible 的 SSH 错误
Posted
技术标签:
【中文标题】Ansible:ansible 的 SSH 错误【英文标题】:Ansible: SSH Error with ansible 【发布时间】:2016-09-14 11:03:57 【问题描述】:我正在主机 A 上部署堆栈,我想在主机 B 上执行配置后脚本。这些脚本应该从 ansible 控制器(主机 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
我正在尝试使用“何时”的方法并得到相同的错误。
库存文件有两个主机,都被隔离在不同的组中。
[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
我还在日志中注意到 ansible 跳过是在 10.17.10.150 上执行 python 脚本。
我希望 ansible 在 10.17.10.85 上执行 python 脚本, 而不是 10.17.10.150。
【问题讨论】:
【参考方案1】:我找到了答案..! sudo_exe = su myuser
已在 ansible.cfg 文件中启用!
【讨论】:
以上是关于Ansible:ansible 的 SSH 错误的主要内容,如果未能解决你的问题,请参考以下文章