播放过程中出现SSH错误 [英] Ansible SSH error during play

查看:82
本文介绍了播放过程中出现SSH错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Ansible中遇到一个奇怪的错误.首先,第一个角色可以正常工作,但是当Ansible尝试执行第二个角色时,由于ssh错误而失败.

I get a strange error with Ansible. First of all, the first role works fine but when Ansible tries to execute the seconde one it failed because of ssh error.

环境:

  • 操作系统:CentOS 7
  • 可用的版本:2.2.1.0
  • Python版本:2.7.5
  • OpenSSH版本:OpenSSH_6.6.1p1,OpenSSL 1.0.1e-fips 2013年2月11日

已执行的Ansible命令:

ansible-playbook -vvvv -i inventory/dev playbook_update_system.yml --limit "db[0]"

剧本:

- name: "HUB Playbook | Updating system packages on {{ ansible_hostname }}"
  hosts: release_first_half
  roles:
    - upgrade_system_package
    - reboot_server

角色:upgrade_system_package :

- name: "upgrading CentOS system packages on {{ ansible_hostname }}"
  shell: sudo puppet apply -e 'exec{"upgrade-package":command => "/usr/bin/yum clean all; /usr/bin/yum -y update;"}'
  when: ansible_distribution == 'CentOS' and 'cassandra' not in group_names

角色:reboot_server :

- name: "reboot CentOS [{{ ansible_hostname }}] server"
  shell: sudo puppet apply -e 'exec{"reboot-os":command => "/usr/sbin/reboot"}'
  when: ansible_distribution == 'CentOS' and 'cassandra' not in group_names

当前行为:

  1. 连接到"db1"节点并执行角色升级系统软件包" =>确定
  2. 尝试连接到"db1"并执行角色"reboot_server" =>由于ssh而失败.

Ansible返回的错误消息:

致命:[db1]:无法连接! => { 已更改":错误, "msg":无法通过ssh连接到主机:OpenSSH_6.6.1,OpenSSL 1.0.1e-fips 2013年2月11日\ r \ ndebug1:读取配置数据/USR/newtprod/.ssh/config\r\ndebug1:读取配置数据/etc/ssh/ssh_config \ r \ ndebug1:/etc/ssh/ssh_config第56行:为* \ r \ ndebug1应用选项:自动多路复用:尝试现有的master \ r \ ndebug2:fd 3设置O_NONBLOCK \ r \ ndebug2:mux_client_hello_exchange:主版本4 \ r \ ndebug3:mux_client_forwards:请求转发:0本地,0远程\ r \ ndebug3:mux_client_request_session:输入\ r \ ndebug3:mux_client_request_alive:输入\ r \ ndebug3:mux_client_994:已完成r \ ndebug3:mux_client_request_session:发送会话请求\ r \ ndebug1:mux_client_request_session:主会话ID:2 \ r \ ndebug3:mux_client_read_packet:读取头失败:管道损坏\ r \ ndebug2:控制主节点意外终止\ r \ n与db1的共享连接已关闭.\ r \ n, 无法访问":是 }

fatal: [db1]: UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /USR/newtprod/.ssh/config\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 64994\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Control master terminated unexpectedly\r\nShared connection to db1 closed.\r\n", "unreachable": true }

我不明白,因为先前的角色已在此节点上成功执行.而且,我们有很多剧本都使用相同的清单文件,而且它们的工作原理还不错.我也尝试了另一个节点,但结果相同.

I don't understand because the previous role has been executed successfully on this node. Moreover, we have a lot of playbook which are using same inventory file and they works fine. I tried on another node too but same result.

推荐答案

这是一个简单而众所周知的问题:关闭过程会导致SSH守护程序退出,这会中断当前的SSH会话(您会得到断管道"错误).服务器正常重启,但是Ansible流被中断.

It's a simple and pretty well-known issue: the shutdown process causes SSH daemon to quit and this breaks the current SSH session (you get the "broken pipe" error). The server reboots properly, but Ansible flow gets interrupted.

您需要在shell命令中添加一个延迟,并使用async选项运行它,以便Ansible的SSH会话可以在被杀死之前完成.

You need to add a delay to your shell command and run it with async option, so that Ansible's SSH session can finish before it gets killed.

shell: sleep 5; sudo puppet apply -e 'exec{"reboot-os":command => "/usr/sbin/reboot"}'
async: 0
poll: 0

这篇关于播放过程中出现SSH错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆