如何处理 ansible ios_config 模块中的预期提示 [英] How to handle expected prompt in ansible ios_config module
问题描述
我正在尝试使用 Ansible(ios_config 模块)在 cisco ios 设备上实现几个简单的命令.
I am trying to implement couple simple commands on cisco ios devices using Ansible (ios_config module).
特别是,我想删除用户个人资料,但它需要在提示时回答并且我收到超时错误...
Especially, I want to remove user profile, but it requires to answer on a prompt and I am getting timeout error...
我注意到ios_command模块中有prompt/answer参数,但是ios_config模块好像不支持.
I have noticed that there are prompt/answer parameters in ios_command module, but it seems that it is not supported in ios_config module.
有人遇到过类似的问题吗?
Has anyone run into the similar problem?
Ansible 任务:
- name: remove user on remote devices
ios_config:
lines:
- no username testuser
provider: "{{ provider }}"
来自 Cisco 设备的输出:
Cisco_Router(config)#no username testuser
This operation will remove all username related configurations with same name.Do you want to continue? [confirm]
剧本输出:
TASK [remove user on remote devices] *************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.module_utils.connection.ConnectionError: timeout trying to send command: end
fatal: [Cisco_Router]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_3_OlXK/ansible_module_ios_config.py\", line 583, in <module>\n main()\n File \"/tmp/ansible_3_OlXK/ansible_module_ios_config.py\", line 512, in main\n load_config(module, commands)\n File \"/tmp/ansible_3_OlXK/ansible_modlib.zip/ansible/module_utils/network/ios/ios.py\", line 168, in load_config\n File \"/tmp/ansible_3_OlXK/ansible_modlib.zip/ansible/module_utils/connection.py\", line 149, in __rpc__\nansible.module_utils.connection.ConnectionError: timeout trying to send command: end\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1}
推荐答案
从 Ansible 2.4 开始,有一个 ios_user
模块可用于创建、编辑和删除用户.
Starting with Ansible 2.4 there is an ios_user
module that can be used to create, edit and remove users.
- name: set user view/role
ios_user:
name: testuser
state: absent
provider: "{{ provider }}"
完整文档和更多示例可在以下位置找到:https://docs.ansible.com/ansible/latest/modules/ios_user_module.html
The full documentation and further examples can be found at: https://docs.ansible.com/ansible/latest/modules/ios_user_module.html
各种_command
模块,包括ios_command
支持传递提示.
The various _command
modules, including ios_command
support passing prompts.
例如:
- name: run commands that require answering a prompt
ios_command:
commands:
- command: 'clear counters GigabitEthernet0/1'
prompt: 'Clear "show interface" counters on this interface \[confirm\]'
answer: 'y'
- command: 'clear counters GigabitEthernet0/2'
prompt: '[confirm]'
answer: "\r"
参见 https://docs.ansible.com/ansible/latest/modules/ios_command_module.html 了解更多信息.
See https://docs.ansible.com/ansible/latest/modules/ios_command_module.html for further info.
这篇关于如何处理 ansible ios_config 模块中的预期提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!