我正在尝试使用ansible在我们的Cisco设备上进行一些自动化操作
剧本
- name: change config
hosts: switches
gather_facts: false
tasks:
- name: add an acl
ios_config:
lines:
- ip access-list standard 7 permit 172.16.1.0 0.0.0.255
主机文件
[switches]
sw1 ansible_host=172.16.1.1
group_vars \ switches.yml
ansible_connection: network_cli
ansible_network_os: ios
ansible_become: yes
ansible_become_method: enable
ansible_ssh_user: *****
ansible_ssh_pass: *****
ansible_become_pass: ******
如果我只是执行ios_command,则根本没有问题,但是,如果我尝试使用ios_config更改配置,我将得到以下错误。
[sw1]: FAILED! => {"msg": "unable to elevate privilege to enable mode, at prompt [None] with error: timeout trying to send command: enable"}
顺风顺水
3Fb>en
HCC password:
3Fb#
我们有一个非默认的提示,如何更改ansible以匹配此提示,是否还需要进行其他操作以解决此问题。谢谢。
答案 0 :(得分:0)
[sw1]:失败! => {“ msg”:“无法提升特权以启用模式,在提示[无]时出现错误:尝试发送命令超时:启用”}
Q:“ We have a non-default prompt, how to change on ansible to match this?
”
A:恕我直言,它与提示无关。 _exec_cli_command 失败并显示“ error: timeout trying to send command: enable
”后,提示默认为NONE。参见nxos.py
try:
self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict'))
prompt = self._get_prompt()
if prompt is None or not prompt.strip().endswith(b'enable#'):
raise AnsibleConnectionFailure('failed to elevate privilege to enable mode still at prompt [%s]' % prompt)
except AnsibleConnectionFailure as e:
prompt = self._get_prompt()
raise AnsibleConnectionFailure('unable to elevate privilege to enable mode, at prompt [%s] with error: %s' % (prompt, e.message)
您可能想从connection.py的“ exec_command
”开始调试