“无法找到'可连接'的位置请设置或检查ANSIBLE_CONNECTION_PATH的值”

问题描述

库存文件-/ home / Alan / hosts

[routers]
rter1 ansible_network_os=ios ansible_connection=network_cli
rter2 ansible_network_os=ios ansible_connection=network_cli

Ansible.cfg文件/home/Alan/ansible.cfg

[defaults]

# Use local hosts file in folder
inventory = /home/Alan/hosts
#library = /usr/share/my_modules/
#module_utils = /usr/share/my_module_utils
host_key_checking = False

retry_files_enabled = False

gathering = explicit

#interpreter_python = /usr/bin/python3

Ansible Playbook:/home/Alan/getver1.yml

---
-
  name: "show version and other user level commands"
  gather_facts: false
  hosts: routers

  tasks:
    -
      ios_command:
        commands:
          - "show version"
          - "show ip int brief"
      name: "run multiple commands on remote nodes"
      register: print_output
    -
      debug: var=print_output.stdout_lines

Ansible --version输出

ansible 2.9.11
  config file = /home/Alan/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules','/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default,Sep 26 2019,11:57:09) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

运行剧本的命令:

ansible-playbook getver1.yml -u alan -k

运行命令会导致此错误。我该怎么办?

"Unable to find location of 'ansible-connection'. Please set or check the value of ANSIBLE_CONNECTION_PATH"

解决方法

是不是您的ansible.cfg没有指向正确的库存路径?

您说库存位于/ home / Alan / hosts,但是库存变量(在ansible.cfg内部)指向./hosts

您可以将您的特权更改为:

[routers]
rter1
rter2

[routers:vars]
ansible_network_os=ios
ansible_connection=network_cli
,

我遇到了同样的问题,事实证明,升级的ansible软件包是引发此问题的元凶。

即从2.9.13降级到2.9.9对我有用:


wget [ansible软件包的2.9.9版] 就我而言:https://apt.progress-linux.org/archive/engywuck-backports/ansible/2.9.9+dfsg-1~progress5+u1_all/ansible_2.9.9+dfsg-1~progress5+u1_all.deb

dpkg -i ansible_2.9.9 + dfsg-1〜progress5 + u1_all.deb

回声保持| dpkg --set-selections


作为不同的数据包管理器/分发者的YMMV并不是我作为网络工程师的领域。

ansing 可能的ansible network_cli.py中的此更改可能是问题的根源 https://git.progress-linux.org/packages/engywuck-backports/ansible/diff/lib/ansible/plugins/connection/network_cli.py?id=30d592aedfeb7b0f296b30c3c8c5ed18219f4692

,

对于Ansible Debian软件包2.9.13 + dfsg-1。

检查ansible连接路径:

if key == next(reversed(dic.keys())):

如果/ usr / lib / ansible不存在,则可以添加它

# ls -l /usr/bin/ansible-connection
lrwxrwxrwx 1 root root 57 Sep 11 07:32 /usr/bin/ansible-connection -> ../lib/ansible/cli/scripts/ansible_connection_cli_stub.py
# ls -l /usr/lib/ansible
ls: cannot access '/usr/lib/ansible': No such file or directory

然后,您可以安装paramiko

# ln -s /usr/lib/python3/dist-packages/ansible /usr/lib/