【问题标题】:Odd error when attempting net_put via Ansible通过 Ansible 尝试 net_put 时出现奇怪错误
【发布时间】:2023-01-13 03:56:37
【问题描述】:

寻求解决奇怪错误的帮助我正在使用剧本进行故障排除。

我有一个到交换机的工作 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

【问题讨论】:

    标签: networking ansible network-programming scp cisco-ios


    【解决方案1】:

    了解它是什么类型的连接以及什么平台会很有帮助。

    我从文件中看到它是一个 Cisco IOS 设备。你有以下设置吗?

    ansible_connection: ansible.netcommon.network_cli
    ansible_network_os: cisco.ios.ios
    

    以下文档提到了对 paramiko 的需求。如果将 ssh_type 更改为 paramiko,它会起作用吗?

    https://docs.ansible.com/ansible/latest/collections/ansible/netcommon/net_put_module.html

    ssh_type 可以设置如下:

    配置:

    INI 条目: [持续连接] ssh_type = paramiko

    环境变量:ANSIBLE_NETWORK_CLI_SSH_TYPE

    变量:ansible_network_cli_ssh_type

    变量:ansible_network_cli_ssh_type

    【讨论】:

    • 是的,那是我的错。几天来我一直在与这个问题作斗争,有点疲惫不堪。它是思科 C2960X。我在我的对象清单文件中提到了两行。在尝试 net_put 之前,我可以看到引用其 Cisco 和导入 IOS 模块的日志。我的印象是我不能将 Paramiko 与非标准端口一起使用。那是对的吗?
    • 我不经常使用 Ansible,但我不记得有一个带有 paramiko 和非标准端口的问题。 docs.ansible.com/ansible/latest/collections/ansible/netcommon/…
    【解决方案2】:

    我遇到了同样的错误。我能够通过切换回 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-27
      • 2015-12-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多