ansible - Ansible Fetch 模块错误 - 由 ssh_config 导致的管道损坏
问题描述
使用 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 }}'
解决方案
在您的ansible.cfg
中,添加:
[ssh_connection]
ssh_args =
这将删除-o ControlMaster=auto -o ControlPersist=60s
我认为导致问题的原因。
ansible_connection=netconf
当您在连接到网络设备时忘记添加时,我还发现这是一个问题。在这种情况下,您将不需要上述修复。
推荐阅读
- java - 内容根 一个项目中的两个模块不能共享同一个内容根。IntelliJ 将模块添加到 Java 项目
- powerbi - Azure Blob 中的 Power BI 增量刷新
- java - Android:在枚举类中获取本地资源
- python-3.x - 结合使用 itertools 和 zip 从两个不同长度的列表创建字典时出现问题
- python - Python无法进行矩阵求和
- python-3.x - 如何在 Django 中将测试实例 ID 分开?
- visual-studio-code - 如何在 VS Code 中找到不是 utf8 的 unicode 字符?
- r - 访问带引号的点参数的名称
- python - 在python中调用父类
- html - 如何使用节点 js 和处理程序栏将 BLOB 对象从 mysql DB 解码为 png 图像以显示在目录中