【问题标题】:Ansible SSH error during play播放期间的 Ansible SSH 错误
【发布时间】:2017-08-31 06:54:14
【问题描述】:

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

环境

  • 操作系统:CentOS 7
  • Ansible 版本: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”节点并执行角色“升级系统包” => OK
  2. 尝试连接到“db1”并执行角色“rebo​​ot_server” => 由于 ssh 失败。

Ansible 返回的错误信息

致命:[db1]:无法访问! => { “改变”:错误, "msg": "通过 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配置数据 /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:主版本 4\r\ndebug3:mux_client_forwards:请求转发:0 本地,0 远程\r\ndebug3:mux_client_request_session:进入\r\ndebug3:mux_client_request_alive:进入\r\ndebug3:mux_client_request_alive:完成 pid = 64994\ 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", “无法到达”:是的 }

我不明白,因为之前的角色已经在这个节点上成功执行了。此外,我们有很多使用相同库存文件的剧本,它们运行良好。我也在另一个节点上尝试过,但结果相同。

【问题讨论】:

    标签: ssh ansible ansible-2.x


    【解决方案1】:

    这是一个简单而广为人知的问题:关闭进程会导致 SSH 守护进程退出,这会中断当前的 SSH 会话(您会收到“broken pipe”错误)。服务器正常重启,但 Ansible 流程被中断。

    您需要为您的shell 命令添加延迟并使用async 选项运行它,以便 Ansible 的 SSH 会话可以在它被终止之前完成。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多