我正在尝试使用Ansible Junos模块中的juniper_junos_facts来查询我使用Vagrant提供的一些VM。但是,我得到了以下错误。
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时,所有这些看起来都是正常的。
~/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获得的以下文档中复制的。
我的库存文件
[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我的剧本
---
- 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发布于 2019-03-28 12:20:30
在使用connection: local时,需要向模块提供完整的连接细节(通常在播放级别打包在提供者字典中以减少重复):
- 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“方法,您的剧本应该如下所示:
---
- 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发布于 2020-04-29 18:51:45
这是给那些通过错误信息发现这个问题的人的答案。
如果您使用与local不同的连接插件,它可以,并且通常是由此错误引起的,与变量排序有关。
版本2.2.1及更高版本中已经修复的Bug,请尝试从Galaxy更新模块。
https://stackoverflow.com/questions/55263504
复制相似问题