ansible.netcommon.telnet 模块 – 执行一个低级的、不规范的 telnet 命令

注意

此模块是 ansible.netcommon 集合(版本 7.1.0)的一部分。

如果您正在使用 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install ansible.netcommon

要在 playbook 中使用它,请指定:ansible.netcommon.telnet

ansible.netcommon 1.0.0 中的新增功能

概要

  • 执行一个低级的、不规范的 telnet 命令,不通过模块子系统。

  • 这主要用于在默认情况下仅启用 telnet 的设备上启用 ssh。

注意

此模块具有对应的 action 插件

参数

参数

注释

command

别名: commands

列表 / 元素=字符串 / 必需

要在 telnet 会话中执行的命令列表。

crlf

布尔值

发送一个 CRLF(回车换行),而不仅仅是一个 LF(换行)。

选项

  • false ← (默认)

  • true

host

字符串

执行命令的主机/目标

默认值: "remote_addr"

login_prompt

字符串

要期望的登录或用户名提示符

默认值: "login: "

password

字符串

登录密码

password_prompt

字符串

要期望的登录或用户名提示符

默认值: "Password: "

pause

整数

每个命令之间暂停的秒数

默认值: 1

port

整数

要使用的远程端口

默认值: 23

prompts

列表 / 元素=字符串

发送下一个命令之前期望的提示符列表

默认值: ["$"]

send_newline

布尔值

成功连接后发送一个换行符以启动终端会话。

选项

  • false ← (默认)

  • true

timeout

整数

远程操作的超时时间

默认值: 120

user

字符串

登录用户

默认值: "remote_user"

注意事项

注意

  • environment 关键字不适用于此任务

示例

- name: send configuration commands to IOS
  ansible.netcommon.telnet:
    user: cisco
    password: cisco
    login_prompt: "Username: "
    prompts:
      - "[>#]"
    command:
      - terminal length 0
      - configure terminal
      - hostname ios01

- name: run show commands
  ansible.netcommon.telnet:
    user: cisco
    password: cisco
    login_prompt: "Username: "
    prompts:
      - "[>#]"
    command:
      - terminal length 0
      - show version

返回值

常见返回值记录在此处,以下是此模块特有的字段

描述

output

列表 / 元素=字符串

每个命令的输出是此列表中的一个元素

返回值: 总是

示例: ["success", "success", "", "warning .. something"]

作者

  • Ansible 核心团队