首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法建立PyEZ连接: ConnectUnknownHostError

无法建立PyEZ连接: ConnectUnknownHostError
EN

Stack Overflow用户
提问于 2019-03-20 14:43:06
回答 2查看 1.9K关注 0票数 0

我正在尝试使用Ansible Junos模块中的juniper_junos_facts来查询我使用Vagrant提供的一些VM。但是,我得到了以下错误。

代码语言:javascript
运行
复制
fatal: [r1]: FAILED! => {"changed": false, "msg": "Unable to make a PyEZ connection: ConnectUnknownHostError(r1)"}
fatal: [r2]: FAILED! => {"changed": false, "msg": "Unable to make a PyEZ connection: ConnectUnknownHostError(r2)"}

我在下面的文档这里 on juniper.net中看到,当您在库存文件中没有正确定义主机时,就会发生此错误。我不认为这是我的库存文件的问题,因为当我运行-ansible- inventory -host时,所有这些看起来都是正常的。

代码语言:javascript
运行
复制
~/vagrant-projects/junos$ ansible-inventory --host r1
{
    "ansible_ssh_host": "127.0.0.1", 
    "ansible_ssh_port": 2222, 
    "ansible_ssh_private_key_file": ".vagrant/machines/r1/virtualbox/private_key", 
    "ansible_ssh_user": "root"
}
~/vagrant-projects/junos$ ansible-inventory --host r2
{
    "ansible_ssh_host": "127.0.0.1", 
    "ansible_ssh_port": 2200, 
    "ansible_ssh_private_key_file": ".vagrant/machines/r2/virtualbox/private_key", 
    "ansible_ssh_user": "root"
}

我的剧本是从我从这里 on juniper.net获得的以下文档中复制的。

我的库存文件

代码语言:javascript
运行
复制
[vsrx]
r1 ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 ansible_ssh_private_key_file=.vagrant/machines/r1/virtualbox/private_key
r2 ansible_ssh_host=127.0.0.1 ansible_ssh_port=2200 ansible_ssh_private_key_file=.vagrant/machines/r2/virtualbox/private_key

[vsrx:vars]
ansible_ssh_user=root

我的剧本

代码语言:javascript
运行
复制
---
- name: show version
  hosts: vsrx
  roles:
    - Juniper.junos
  connection: local
  gather_facts: no

  tasks:
    - name: retrieve facts
      juniper_junos_facts:
        host: "{{ inventory_hostname }}"
        savedir: "{{ playbook_dir }}"
    - name: print version
      debug:
        var: junos.version
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-03-28 12:20:30

在使用connection: local时,需要向模块提供完整的连接细节(通常在播放级别打包在提供者字典中以减少重复):

代码语言:javascript
运行
复制
    - name: retrieve facts
      juniper_junos_facts:
        host: "{{ ansible_ssh_host }}"
        port: "{{ ansible_ssh_port }}"
        user: "{{ ansible_ssh_user }}"
        passwd: "{{ ansible_ssh_pass }}"
        ssh_private_key_file: "{{ ansible_ssh_private_key_file }}" 
        savedir: "{{ playbook_dir }}"

完整的文档在这里(注意URL中正确的角色版本):facts.html,在这里您还可以看到默认值是什么。

要充分解释"provider“方法,您的剧本应该如下所示:

代码语言:javascript
运行
复制
---
- name: show version
  hosts: vsrx
  roles:
    - Juniper.junos
  connection: local
  gather_facts: no

  vars:
    connection_info:
        host: "{{ ansible_ssh_host }}"
        port: "{{ ansible_ssh_port }}"
        user: "{{ ansible_ssh_user }}"
        passwd: "{{ ansible_ssh_pass }}"
        ssh_private_key_file: "{{ ansible_ssh_private_key_file }}" 

  tasks:
    - name: retrieve facts
      juniper_junos_facts:
        provider: "{{ connection_info }}"
        savedir: "{{ playbook_dir }}"
    - name: print version
      debug:
        var: junos.version
票数 1
EN

Stack Overflow用户

发布于 2020-04-29 18:51:45

这是给那些通过错误信息发现这个问题的人的答案。

如果您使用与local不同的连接插件,它可以,并且通常是由此错误引起的,与变量排序有关。

版本2.2.1及更高版本中已经修复的Bug,请尝试从Galaxy更新模块。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55263504

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档