【问题标题】:"Unable to find location of 'ansible-connection'. Please set or check the value of ANSIBLE_CONNECTION_PATH"“无法找到 'ansible-connection' 的位置。请设置或检查 ANSIBLE_CONNECTION_PATH 的值”
【发布时间】:2020-08-27 12:03:09
【问题描述】:

库存文件 - /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 剧本:/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-inventory -i hosts --list 时 ANSIBLE_CONNECTION 有什么价值?

标签: ansible ansible-inventory


【解决方案1】:

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

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

您能否将您的库存更改为:

[routers]
rter1
rter2

[routers:vars]
ansible_network_os=ios
ansible_connection=network_cli

【讨论】:

  • 我更新了 /home/Alan/hosts 的路径,但仍然出现同样的错误
【解决方案2】:

我遇到了同样的问题,原来升级的 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

echo ansible 保持 | dpkg --set-selections


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

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

【讨论】:

    【解决方案3】:

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

    检查 ansible-connection 路径:

    # 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
    

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

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

    然后,你可以安装 paramiko

    # apt install python3-paramiko
    

    【讨论】:

      猜你喜欢
      • 2018-08-25
      • 2016-03-04
      • 2018-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多