在管理 Junos 设备时,排除 Ansible 身份验证错误
以下部分概述了使用 Ansible 管理 Junos 设备时可能遇到的身份验证错误。这些部分还介绍了每个错误的潜在原因和解决方案。
ConnectAuthError 问题疑难解答
问题
描述
在模块执行 juniper.device
期间,Ansible 控制节点会生成 ConnectAuthError
身份验证失败错误。例如:
"msg": "Unable to make a PyEZ connection: ConnectAuthError(dc1a.example.net)"
原因
Junos 设备可能无法对用户进行身份验证,原因如下:
-
用户在 Junos 设备上没有帐户。
-
用户的帐户在 Junos 设备上配置了基于文本的密码,但在执行模块时为用户提供了错误的密码或未提供密码。
-
用户在配置了 SSH 密钥的 Junos 设备上拥有帐户,但设备或控制节点上无法访问 SSH 密钥。
溶液
确保执行模块的用户在所有目标 Junos 设备上都具有 Junos OS 登录帐户,并为该帐户配置了 SSH 公钥/私钥对或基于文本的密码。如果配置了 SSH 密钥,请验证用户是否可以访问它们。有关更多信息,请参阅 对在 Junos 设备上执行 Ansible 模块的用户进行身份验证。
属性conn_type错误疑难解答
问题
描述
在 Junos 设备上执行 juniper.device
模块期间,Ansible 控制节点生成以下错误:
AttributeError: 'JuniperJunosModule' object has no attribute 'conn_type'
原因
虽然较旧的、不推荐 Juniper.junos
使用的模块支持使用 provider
字典来定义连接和身份验证参数,但这些 juniper.device
模块不支持使用 provider
字典,如果引用了字典,则会生成上述错误。
溶液
如果您在模块操作指南 juniper.device
中提供了连接和身份验证参数,则必须在适合 Ansible 连接的位置定义参数。对于持久连接 (connection: juniper.device.pyez
),请在该 vars:
部分下定义参数。对于本地连接 (connection: local
),请在部分下 vars:
定义参数或作为顶级模块参数。例如:
--- - name: Get device facts hosts: dc1 connection: juniper.device.pyez gather_facts: no vars_prompt: - name: "DEVICE_PASSWORD" prompt: "Device password" private: yes vars: passwd: "{{ DEVICE_PASSWORD }}" tasks: - name: Get device facts juniper.device.facts: savedir: "{{ playbook_dir }}"
--- - name: Get device facts hosts: dc1 connection: local gather_facts: no vars_prompt: - name: "DEVICE_PASSWORD" prompt: "Device password" private: yes tasks: - name: Get device facts juniper.device.facts: passwd: "{{ DEVICE_PASSWORD }}" savedir: "{{ playbook_dir }}"