没有用户名登录的 Ansible telnet
Ansible telnet without username login
我需要使用 ansible telnet 模块连接到 cisco 设备(我无法启用 SSH)。
我在网上找到的所有教程,都是在指定登录用户名和密码进行telnet认证。
但是我的路由器不需要用户名,授权提示直接以消息开始:
Password:
这是我的文件:
inventory.yml :
[cisco]
test ip_address=xxx.yyy.zzz
[cisco:vars]
password=test
password_enable=test
plays/cisco.yml :
---
- hosts: cisco
connection: local
roles:
- role: cisco-telnet
roles/cisco-telnet/tasks/main.yml :
---
- name: Telnet test
telnet:
host: "{{ ip_address }}"
port: 23
password_prompt: "Password:"
password: "{{ password }}"
prompts:
- '[>|#]'
command:
- enable
- "{{ password_enable }}"
- show running-config
我每次都收到一条错误消息:
FAILED! => {
"msg": "Unexpected failure during module execution.",
"stdout": ""
}
如何在不指定用户名的情况下使用 telnet 模块?有人已经这样做了吗?
研究 telnet module and reading the documentation 的源代码,我假设以下行为:
If the password
is empty then no password prompt
is expected.
因此,您可以将 login prompt
用于 password
。有点奇怪,所以我想下面的代码片段应该可以工作:
- name: Telnet test
telnet:
host: "{{ ip_address }}"
port: 23
login_prompt: "Password:"
user: "{{ password }}"
prompts:
- '[>|#]'
command:
- enable
- "{{ password_enable }}"
- show running-config
我无法测试它,因为我没有 telnet 服务器了,你迟到了 20 年;-)
我需要使用 ansible telnet 模块连接到 cisco 设备(我无法启用 SSH)。 我在网上找到的所有教程,都是在指定登录用户名和密码进行telnet认证。
但是我的路由器不需要用户名,授权提示直接以消息开始:
Password:
这是我的文件:
inventory.yml :
[cisco]
test ip_address=xxx.yyy.zzz
[cisco:vars]
password=test
password_enable=test
plays/cisco.yml :
---
- hosts: cisco
connection: local
roles:
- role: cisco-telnet
roles/cisco-telnet/tasks/main.yml :
---
- name: Telnet test
telnet:
host: "{{ ip_address }}"
port: 23
password_prompt: "Password:"
password: "{{ password }}"
prompts:
- '[>|#]'
command:
- enable
- "{{ password_enable }}"
- show running-config
我每次都收到一条错误消息:
FAILED! => {
"msg": "Unexpected failure during module execution.",
"stdout": ""
}
如何在不指定用户名的情况下使用 telnet 模块?有人已经这样做了吗?
研究 telnet module and reading the documentation 的源代码,我假设以下行为:
If the
password
is empty then nopassword prompt
is expected.
因此,您可以将 login prompt
用于 password
。有点奇怪,所以我想下面的代码片段应该可以工作:
- name: Telnet test
telnet:
host: "{{ ip_address }}"
port: 23
login_prompt: "Password:"
user: "{{ password }}"
prompts:
- '[>|#]'
command:
- enable
- "{{ password_enable }}"
- show running-config
我无法测试它,因为我没有 telnet 服务器了,你迟到了 20 年;-)