首页 > 解决方案 > connect() 得到了一个意外的关键字参数 'sock'

问题描述

尝试连接到路由器时出现以下错误,并且我正在运行最新版本的 Paramiko。什么可能导致此错误,是否有任何解决方法?

更新:它的简单脚本使用 ansible 来收集“显示系统正常运行时间”命令输出。

我有清单文件,其中包含路由器的 IP 地址

$ cat uptime.yaml 
---
- name: Get device uptime
  hosts:
    - all
  connection: local
  gather_facts: no
  
  vars_prompt:
    - name: username
      prompt: UsernName
      private: no
    
    - name: password
      prompt: Password
      private: yes

  tasks:
    - name: get uptime using ansible moduel
      junos_command:
        commands:
          - show system uptime
        provider:
          host: "{{ansible_host}}"
          port: 22
          username: "{{ username }}"
          password: "{{ password }}"

>>> print(paramiko.__version__)
2.7.2


[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.9 (default, Jan 26 2021, 15:33:00) [GCC 8.4.0]. This feature 
will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
UsernName: regress
Password: 

PLAY [Get device uptime] ************************************************************************************************************************************************************************

TASK [get uptime using ansible moduel] **********************************************************************************************************************************************************
[WARNING]: ['connection local support for this module is deprecated and will be removed in version 2.14, use connection ansible.netcommon.netconf']
fatal: [R1_re0]: FAILED! => {"changed": false, "msg": "connect() got an unexpected keyword argument 'sock'"}
fatal: [R2_re0]: FAILED! => {"changed": false, "msg": "connect() got an unexpected keyword argument 'sock'"}

PLAY RECAP **************************************************************************************************************************************************************************************
R1_re0                     : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
R2_re0                     : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

标签: python-3.xansible

解决方案


推荐阅读