ansible2.14使用cisco Failed to resolve hostname inventory_hostname

140 阅读1分钟

ansible2.14使用cisco.ios相关模块报错ssh connect failed: Failed to resolve hostname inventory_hostname 问题排查

playbook如下:

- name: "Demonstarte commection to switchs"
  hosts: ios
  gather_facts: no
  tasks:
    - name: "Gather fasts"
      cisco.ios.ios_facts:
        gather_subset: all

首先,看到这个问题第一反应是无法解析主机名,要么是dns问题要么是hosts文件里面主机没有指定ip地址导致主机名无法解析而无法找到主机修改host文件如下(自己使用注意替换相关项目提供的文件已脱敏):

[all:vars]
ansible_connection=ansible.netcommon.network_cli
ansible_user=your username
[ios]
R2 ansible_host=your ip address inventory_hostname=your ip address
[ios:vars]
ansible_network_os=cisco.ios.ios
ansible_ssh_pass=your ssh password
ansible_user=your username
anisble_password=your ssh password
host_key_checking=false
ansible_network_cli_ssh_type=paramiko
ansible_command_timeout=200
ansible_connect_timeout=200

其中 ansible_host和inventory_hostname就是指定主机名相关ip地址的项目,文档上说两者等价,我们为了防止出问题都给加上,按理说在文档上ansible_ssh_pass和ansible_password也是等价的,但是测试下只有ansible_ssh_pass生效。

network_cli参考文档

结果,报错依旧。实在没有办法,google百度大法。在stackoverflow上找到这个帖子 链接

I ported the settings and playbook to a diffrerent ansible host at a testing environment. The only difference is there is ansible 2.13 installed. The playbook is running successfull there. So I think there is a problem with version 2.14.

翻译一下就是把ansible版本从2.14换成2.13就把问题解决了。