You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Ansible执行net_put时遇异常错误,寻求技术支持

关于Ansible net_put模块SCP传输文件至交换机失败的问题

已成功通过SSH连接到目标交换机,但使用Ansible net_put 模块通过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

执行的Ansible剧本内容:

- 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

内容的提问来源于stack exchange,提问作者Moridn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 13:35:34