为了寻求解决一个奇怪错误的帮助,我正在使用行动手册进行故障排除。
我有一个到交换机的SSH会话,但很难通过Ansible上的SCP传输文件。我可以直接从同一台服务器启动SCP会话,没有任何问题,也可以传输文本文件(下面引用的是同一个文件(,但它似乎在Ansible中不起作用。
我通过Ansible启用了详细日志记录,这就是我在生成的日志文件中看到的。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/ansible/utils/jsonrpc.py", line 46, in handle_request
result = rpc_method(*args, **kwargs)
File "/root/.ansible/collections/ansible_collections/ansible/netcommon/plugins/connection/network_cli.py", line 1282, in copy_file
self.ssh_type_conn.put_file(source, destination, proto=proto)
File "/root/.ansible/collections/ansible_collections/ansible/netcommon/plugins/connection/libssh.py", line 498, in put_file
raise AnsibleError(
ansible.errors.AnsibleError: Error transferring file to flash:test.txt: Initializing SCP session of remote file [flash:test.txt] for w>
2022-10-06 11:58:35,671 p=535932 u=root n=ansible | fatal: [%remoteSwitch%]: FAILED! => {
"changed": false,
"destination": "flash:test.txt",
"msg": "Exception received: Error transferring file to flash:test.txt: Initializing SCP session of remote file [flash:test.txt] fo>
}
恐怕谷歌在这方面帮不了我太多。如果有帮助的话,这是在Ubuntu 22.04上,带有Ansible 2.10.8。
尝试运行的游戏是:
- hosts: %remoteSwitch%
vars:
- firmware_image_name: "test.txt"
tasks:
- name: Copying image to the switch... This can take time, please wait...
net_put:
src: "/etc/ansible/firmware_images/C2960X/{{ firmware_image_name }}"
dest: "flash:{{ firmware_image_name }}"
vars:
ansible_command_timeout: 20
protocol: scp
我遇到了同样的错误。我能够通过切换回Paramiko SSH来修复它。这可以通过pip uninstall ansible-pylibssh
来实现(注意,这很可能有其他副作用(。
或者,您可以在Ansible播放级别强制使用Paramiko:
---
- name: Test putting a file onto Cisco IOS/IOS-XE device
hosts: cisco1
# ansible-pylibssh errors out here (force paramiko usage)
vars:
ansible_network_cli_ssh_type: paramiko
tasks:
- name: Copy file
ansible.netcommon.net_put:
src: my_file1.txt
dest : flash:/my_file1.txt
protocol: scp
了解它是什么类型的连接以及什么平台会很有帮助。
我从文件中看到,这是一个思科IOS设备。您有以下设置吗?
ansible_connection: ansible.netcommon.network_cli
ansible_network_os: cisco.ios.ios
以下文件提到了对帕拉米科的需要。如果您将ssh_type更改为paramiko,它会起作用吗?
https://docs.ansible.com/ansible/latest/collections/ansible/netcommon/net_put_module.html
ssh_type可以设置如下:
配置:
INI条目:[persistent_connection]ssh_type=paramiko
环境变量:ANSIBLE_NETWORK_CLI_SSH_TYPE
变量:ansible_network_cli_ssh_type
变量:ansible_network_cli_ssh_type