【问题标题】:Ansible Fetch module error - broken pipe caused by ssh_configAnsible Fetch 模块错误 - 由 ssh_config 导致的管道损坏
【发布时间】:2021-03-19 17:47:34
【问题描述】:

使用 fetch 模块时出现模块错误。当我使用-vvvv 运行剧本时,我得到以下调试输出,

debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: resolve_canonicalize: hostname 45.00.00.00 is address
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 = 21668
debug3: mux_client_request_session: session request sent
debug3: mux_client_read_packet: read header failed: Broken pipe
debug2: Received exit status from master 137
Shared connection to 45.00.00.00 closed.

接下来是

SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/maximum/.ansible/cp/1d97f3b2a1 45.00.00.00 '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1605874050.2884061-236476337621921/ > /dev/null 2>&1 && sleep 0'"'"''
<45.63.35.46> (0, b'', b'OpenSSH_8.2p1 Ubuntu-4ubuntu0.1, OpenSSL 1.1.1f  31 Mar 2020\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug2: resolve_canonicalize: hostname 45.00.00.00 is address\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 = 21668\r\ndebug3: mux_client_request_session: session request sent\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
failed: [host1] (item={'path': '/home/domain/backup/archive/archive_2020-11-20.tar.gz', 'mode': '0644', 'isdir': False, 'ischr': False, 'isblk': False, 'isreg': True, 'isfifo': False, 'islnk': False, 'issock': False, 'uid': 0, 'gid': 0, 'size': 101263360, 'inode': 657061, 'dev': 64513, 'nlink': 1, 'atime': 1605858974.1760325, 'mtime': 1605858946.852478, 'ctime': 1605858946.852478, 'gr_name': 'root', 'pw_name': 'root', 'wusr': True, 'rusr': True, 'xusr': False, 'wgrp': False, 'rgrp': True, 'xgrp': False, 'woth': False, 'roth': True, 'xoth': False, 'isuid': False, 'isgid': False}) => {
    "ansible_loop_var": "item",
    "changed": false,
    "item": {
        "atime": 1605858974.1760325,
        "ctime": 1605858946.852478,
        "dev": 64513,
        "gid": 0,
        "gr_name": "root",
        "inode": 657061,
        "isblk": false,
        "ischr": false,
        "isdir": false,
        "isfifo": false,
        "isgid": false,
        "islnk": false,
        "isreg": true,
        "issock": false,
        "isuid": false,
        "mode": "0644",
        "mtime": 1605858946.852478,
        "nlink": 1,
        "path": "/home/domain/backup/archive/archive_2020-11-20.tar.gz",
        "pw_name": "root",
        "rgrp": true,
        "roth": true,
        "rusr": true,
        "size": 101263360,
        "uid": 0,
        "wgrp": false,
        "woth": false,
        "wusr": true,
        "xgrp": false,
        "xoth": false,
        "xusr": false
    },
    "module_stderr": "OpenSSH_8.2p1 Ubuntu-4ubuntu0.1, OpenSSL 1.1.1f  31 Mar 2020\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug2: resolve_canonicalize: hostname 45.00.00.00 is address\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 = 21668\r\ndebug3: mux_client_request_session: session request sent\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 137\r\nShared connection to 45.00.00.00 closed.\r\n",
    "module_stdout": "Killed\r\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 137
}

我主机的 ssh_config 文件导致 fetch 模块出现此错误怎么办? 这刚刚开始发生并且之前已经工作过,我可以成功 ping 我的主机。

这是从我的剧本中运行的实际任务。

- name: Find and register {{ domain_name }} archive
  find:
    paths: /home/{{ domain_name }}/backup/archive/
    file_type: file
    patterns: "*.tar.gz"
  register: tar_file

- debug:
    var: tar_file

- name: Fetch {{ domain_name }} archive for offsite backup
  fetch:
    src: '{{ item.path }}'
    dest: '{{ store_path }}'
    fail_on_missing: yes
  with_items: '{{ tar_file.files }}'

【问题讨论】:

  • 我在 ssh_config 中标记了第 19 行。 Fetch 仍然无法工作,因为它现在似乎认为我是一个无效的攻击者?我设置了 ssh 密钥,所有其他任务都可以正常工作。 `systemctl status ssh``的输出 Nov 22 01:42:32 server sshd[12626]: Invalid user mailman from 171.000.251.00 port 38924 Nov 22 01:42:37 server sshd[12626]: Connection closed by invalid user mailman 171.000 .251.00 端口 38924 [preauth] `
  • 你解决过这个问题吗?
  • 不完全。我相信我试图获取的文件太大,这就是我遇到问题的原因。我尽可能地减小了文件大小,它开始工作了。

标签: ansible fetch ssh-config


【解决方案1】:

在您的ansible.cfg 中,添加:

[ssh_connection]
ssh_args =

这将删除我认为导致问题的-o ControlMaster=auto -o ControlPersist=60s

当您在连接到网络设备时忘记添加ansible_connection=netconf 时,我还发现这是一个问题。在这种情况下,您将不需要上述修复。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-21
    • 1970-01-01
    • 2014-04-28
    • 2011-02-12
    • 2015-07-13
    • 1970-01-01
    相关资源
    最近更新 更多