![EdgeOS Ansible 问题](https://linux22.com/image/780597/EdgeOS%20Ansible%20%E9%97%AE%E9%A2%98.png)
尝试使用 edgeos_commandmodule 运行剧本时收到以下信息:
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.module_utils.connection.ConnectionError: ssh connection failed: ssh connect failed: Failed to resolve hostname inventory_hostname (Name or service not known)
fatal: [ADM-TEST]: FAILED! => {
"changed": false,
"module_stderr": "...",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}
其中module_stderr
包含:
Traceback (most recent call last):
File "/home/lowkeylamb/.ansible/tmp/ansible-local-5582d70859ti/ansible-tmp-1663885370.4466758-5712-173536800348281/AnsiballZ_edgeos_command.py", line 107, in <module>
_ansiballz_main()
File "/home/lowkeylamb/.ansible/tmp/ansible-local-5582d70859ti/ansible-tmp-1663885370.4466758-5712-173536800348281/AnsiballZ_edgeos_command.py", line 99, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/lowkeylamb/.ansible/tmp/ansible-local-5582d70859ti/ansible-tmp-1663885370.4466758-5712-173536800348281/AnsiballZ_edgeos_command.py", line 47, in invoke_module
runpy.run_module(mod_name='ansible_collections.community.network.plugins.modules.network.edgeos.edgeos_command', init_globals=dict(_module_fqn='ansible_collections.community.network.plugins.modules.network.edgeos.edgeos_command', _modlib_path=modlib_path),
File "/usr/lib/python3.8/runpy.py", line 207, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib/python3.8/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/tmp/ansible_community.network.edgeos_command_payload_blc0ytld/ansible_community.network.edgeos_command_payload.zip/ansible_collections/community/network/plugins/modules/network/edgeos/edgeos_command.py", line 172, in <module>
File "/tmp/ansible_community.network.edgeos_command_payload_blc0ytld/ansible_community.network.edgeos_command_payload.zip/ansible_collections/community/network/plugins/modules/network/edgeos/edgeos_command.py", line 143, in main
File "/tmp/ansible_community.network.edgeos_command_payload_blc0ytld/ansible_community.network.edgeos_command_payload.zip/ansible_collections/community/network/plugins/module_utils/network/edgeos/edgeos.py", line 78, in run_commands
File "/tmp/ansible_community.network.edgeos_command_payload_blc0ytld/ansible_community.network.edgeos_command_payload.zip/ansible_collections/community/network/plugins/module_utils/network/edgeos/edgeos.py", line 44, in get_connection
File "/tmp/ansible_community.network.edgeos_command_payload_blc0ytld/ansible_community.network.edgeos_command_payload.zip/ansible_collections/community/network/plugins/module_utils/network/edgeos/edgeos.py", line 58, in get_capabilities
File "/tmp/ansible_community.network.edgeos_command_payload_blc0ytld/ansible_community.network.edgeos_command_payload.zip/ansible/module_utils/connection.py", line 200, in __rpc__
ansible.module_utils.connection.ConnectionError: ssh connection failed: ssh connect failed: Failed to resolve hostname inventory_hostname (Name or service not known)
这很奇怪,因为我可以顺利地通过 ssh 进入目标设备。我从一个简单的剧本开始,并计划在测试完 edgeos 模块后在此基础上进行构建
以下是剧本:
- name: Update External ERX with latest firmware
hosts: externaledgerouters
remote_user: BudAdmin
tasks:
- name: Update ERX Firmwae
community.network.edgeos_command:
commands: show system image
在我的 ansible.cfg 中,我有指向 hosts 文件的清单
以下是我在 hosts 文件中格式化库存的方法:
externaledgerouters:
hosts:
ADM-TEST:
ansible_host: (ipv4 public IP)
在同一个 hosts 文件底部定义变量:
edgerouters:
vars:
ansible_user: (user)
ansible_port: (port)
ansible_pass: (password)
ansible_connection: network_cli
ansible_network_os: edgeos
children:
externaledgerouters:
我尝试了很多方法来实现它,但都失败了。任何帮助我都感激不尽。
答案1
过了一段时间,我终于搞清楚了。.ssh/known_hosts 文件和运行边缘路由器的剧本存在一些问题
我为两个测试主机重新生成了密钥 ssh-keygen R HOSTNAME - 还必须向本地 known_hosts 文件添加写入权限 chmod +w ~/.ssh/known_hosts - 然后我就可以毫无问题地运行剧本了