community.network.cnos_backup 模块 – 在运行 Lenovo CNOS 的设备上将当前运行或启动配置备份到远程服务器

注意

此模块是 community.network 集合(版本 5.1.0)的一部分。

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

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

要在 playbook 中使用它,请指定:community.network.cnos_backup

注意

community.network 集合已被弃用,将从 Ansible 12 中删除。有关更多信息,请参阅讨论主题

已弃用

在以下版本中删除:

版本 6.0.0

原因:

此集合及其中的所有内容都未维护且已弃用。

替代方案:

未知。

概要

  • 此模块允许您使用交换机配置。它提供了一种将交换机的运行或启动配置备份到远程服务器的方法。这是通过使用 FTP、SFTP、TFTP 或 SCP 定期将网络设备的启动或运行配置的副本保存到远程服务器来实现的。第一步是创建一个目录,以便可以从该目录访问远程服务器。下一步是提供将备份配置的位置的完整文件路径。还必须提供远程服务器所需的身份验证详细信息。此模块使用 SSH 管理网络设备配置。操作结果将放置在一个名为“results”的目录中,该目录必须由用户在其运行 playbook 的本地目录中创建。

别名:network.cnos.cnos_backup

参数

参数

注释

configType

字符串 / 必需

这指定将备份哪种类型的配置。选择项是运行或启动配置。没有默认值,因此如果输入不正确,将导致错误。

选择项

  • "running-config"

  • "startup-config"

deviceType

字符串 / 必需

这指定执行该方法的设备类型。自 Ansible 2.4 起添加了选择项 NE1072T、NE1032、NE1032T、NE10032、NE2572。自 2.8 起添加了选择项 NE0152T

选择项

  • "g8272_cnos"

  • "g8296_cnos"

  • "g8332_cnos"

  • "NE0152T"

  • "NE1072T"

  • "NE1032"

  • "NE1032T"

  • "NE10032"

  • "NE2572"

enablePassword

字符串

配置用于在交换机上进入全局配置命令模式的密码。如果交换机不请求此密码,则忽略该参数。虽然通常该值应该来自清单文件,但您也可以将其指定为变量。此参数是可选的。如果未指定,则不会使用默认值。

host

字符串 / 必需

这是用于在 /etc/ansible/hosts 处搜索主机文件,并标识将应用模板的设备的 IP 地址的变量。通常,Ansible 关键字 {{ inventory_hostname }} 在 playbook 中指定,作为需要配置的网络元素组的抽象。

outputfile

字符串 / 必需

这指定保存每次命令执行输出的文件路径。此处保存合并的模板文件中指定的每个命令以及来自设备的每个响应。通常,该位置是 results 文件夹,但您可以根据您的写入权限选择另一个位置。

password

字符串 / 必需

配置用于验证与远程设备的连接的密码。密码参数的值用于验证 SSH 会话。虽然通常该值应该来自清单文件,但您也可以将其指定为变量。此参数是可选的。如果未指定,则不会使用默认值。

protocol

字符串 / 必需

这指的是网络设备用于与远程服务器交互以上传备份配置的协议。选择项是 FTP、SFTP、TFTP 或 SCP。任何其他协议都会导致错误。如果未指定此参数,则没有默认值可以使用。

选择项

  • "SFTP"

  • "SCP"

  • "FTP"

  • "TFTP"

rcpath

字符串 / 必需

指定配置文件将复制到远程服务器上的完整文件路径。如果使用相对路径作为变量值,则需要指定服务器用户的根文件夹。

rcserverip

字符串 / 必需

- 指定要备份配置的远程服务器的 IP 地址。

serverpassword

字符串 / 必需

指定与所用协议相关的服务器密码。

serverusername

字符串 / 必需

指定与所用协议相关的服务器用户名。

username

字符串 / 必需

配置用于验证与远程设备连接的用户。username 参数的值用于验证 SSH 会话。虽然通常该值应该来自清单文件,您也可以将其指定为变量。此参数是可选的。如果未指定,则不会使用默认值。

备注

注意

示例

Tasks : The following are examples of using the module cnos_backup.
 These are written in the main.yml file of the tasks directory.
---
- name: Test Running Config Backup
  community.network.cnos_backup:
      deviceType: "{{ hostvars[inventory_hostname]['deviceType'] }}"
      outputfile: "./results/test_backup_{{ inventory_hostname }}_output.txt"
      configType: running-config
      protocol: "sftp"
      serverip: "10.241.106.118"
      rcpath: "/root/cnos/G8272-running-config.txt"
      serverusername: "root"
      serverpassword: "root123"

- name: Test Startup Config Backup
  community.network.cnos_backup:
      deviceType: "{{ hostvars[inventory_hostname]['deviceType'] }}"
      outputfile: "./results/test_backup_{{ inventory_hostname }}_output.txt"
      configType: startup-config
      protocol: "sftp"
      serverip: "10.241.106.118"
      rcpath: "/root/cnos/G8272-startup-config.txt"
      serverusername: "root"
      serverpassword: "root123"

- name: Test Running Config Backup -TFTP
  community.network.cnos_backup:
      deviceType: "{{ hostvars[inventory_hostname]['deviceType'] }}"
      outputfile: "./results/test_backup_{{ inventory_hostname }}_output.txt"
      configType: running-config
      protocol: "tftp"
      serverip: "10.241.106.118"
      rcpath: "/anil/G8272-running-config.txt"
      serverusername: "root"
      serverpassword: "root123"

- name: Test Startup Config Backup - TFTP
  community.network.cnos_backup:
      deviceType: "{{ hostvars[inventory_hostname]['deviceType'] }}"
      outputfile: "./results/test_backup_{{ inventory_hostname }}_output.txt"
      configType: startup-config
      protocol: "tftp"
      serverip: "10.241.106.118"
      rcpath: "/anil/G8272-startup-config.txt"
      serverusername: "root"
      serverpassword: "root123"

返回值

常用返回值记录在这里,以下是此模块特有的字段

描述

msg

字符串

成功或失败消息

返回: 总是

示例: "配置 文件 已传输到 服务器"

状态

  • 此模块将在 6.0.0 版本中移除。[已弃用]

  • 有关更多信息,请参阅已弃用

作者

  • Anil Kumar Muraleedharan (@amuraleedhar)