Ansible之管理华为交换机配置


aihuafeng66t
克里斯蒂亚诺诺 2024-01-11 18:10:40 51381 赞同 0 反对 0
分类: 资源 标签: 运维
Ansible之管理华为交换机配置

一、需求说明

  信息系统日常运维中除了服务器,我们还有很多网络设备,比如路由器、交换机、防火墙等。虽然从专业线上分类由主机工程师、网络工程师分别管理,但是在很多小单位可能配置的岗位并不充足,往往是一人身兼数个角色。很荣幸,Ansible也支持网络设备的管理,本文介绍如何使用Ansible管理华为交换机,目前只支持管理CE系列交换机。
环境说明:

  • Ansible主控机操作系统:centos 8.0.1905
  • Ansible版本:2.9.21
  • python版本:3.6.13
  • 交换机型号:CE6800
  • 交换机软件版本:V200R005C10SPC607B607

二、配置步骤

1、查看华为相关的模块

如下所示跟华为相关的模块有68个,均以ce开头
[root@centos8 ~]# ansible-doc -l |grep -i huawei |wc -l
68
[root@centos7 ~]# ansible-doc -l |grep -i huawei
ce_aaa_server Manages AAA server global configuration on HUAWEI CloudEngine switches
ce_aaa_server_host Manages AAA server host configuration on HUAWEI CloudEngine switches
ce_acl Manages base ACL configuration on HUAWEI CloudEngine switches

hwc_network_vpc Creates a Huawei Cloud VPC
hwc_smn_topic Creates a resource of SMNTopic in Huaweicloud Cloud

2、使用ce_command模块查看交换机信息

  • 查看交换机路由信息
    使用命令:[root@centos8 ~]# ansible -m ce_command -a “commands=‘display ip routing-table’ transport=‘cli’ host=192.168.200.100 port=22 username=admin1 password=123456” localhost --connection local

3、配置交换机组的inventory文件

[root@centos8 ansible]# cat switchs
[hw]
192.168.200.100 ansible_ssh_port=22 ansible_ssh_user=admin1 ansible_ssh_pass=123456

4、配置playbook文件

创建备份交换机配置的playbook,备份到目录/tmp/backup
[root@centos7 ansible]# vim ce.yml

[root@centos8 ansible]# cat ce.yaml 
- name: CE switch command test.
  hosts: hw
  connection: local
  gather_facts: no
  vars:
    cli:
      host: "{{ inventory_hostname }}"
      port: "{{ ansible_ssh_port }}"
      username: "{{ ansible_ssh_user }}"
      password: "{{ ansible_ssh_pass }}"
      transport: cli

  tasks:
  - name: configurable backup path
    ce_config:
      lines: sysname {{ inventory_hostname }}
      provider: "{{ cli }}"
      backup: yes
      backup_options:
        filename: backup.cfg
        dir_path: /tmp/backup  


5、执行playbook任务

[root@centos8 ansible]# ansible-playbook -i switchs ce.yaml
在这里插入图片描述

三、QA

1、执行ansible-playbook时报错No module named ‘ncclient’

[root@centos8 ansible]# pip3 install ncclient

2、执行playbook时报错"Unable to decode JSON from response to exec_command(**). Received ‘None’.

在这里插入图片描述
写在最后,尝试了各种python版本、操作系统版本都是报这个错,估计与eNSP模拟器ce6800有关。折腾了3天了,只能放弃了。直接执行是成功的,执行play-book报错没有收到交换机的任何信息。

 

如果您发现该资源为电子书等存在侵权的资源或对该资源描述不正确等,可点击“私信”按钮向作者进行反馈;如作者无回复可进行平台仲裁,我们会在第一时间进行处理!

评价 0 条
克里斯蒂亚诺诺L1
粉丝 0 资源 831 + 关注 私信
最近热门资源
银河麒麟桌面操作系统备份用户数据  130
统信桌面专业版【全盘安装UOS系统】介绍  129
银河麒麟桌面操作系统安装佳能打印机驱动方法  120
银河麒麟桌面操作系统 V10-SP1用户密码修改  108
麒麟系统连接打印机常见问题及解决方法  30
最近下载排行榜
银河麒麟桌面操作系统备份用户数据 0
统信桌面专业版【全盘安装UOS系统】介绍 0
银河麒麟桌面操作系统安装佳能打印机驱动方法 0
银河麒麟桌面操作系统 V10-SP1用户密码修改 0
麒麟系统连接打印机常见问题及解决方法 0
作者收入月榜
1

prtyaa 收益393.62元

2

zlj141319 收益218元

3

1843880570 收益214.2元

4

IT-feng 收益210.13元

5

风晓 收益208.24元

6

777 收益172.71元

7

Fhawking 收益106.6元

8

信创来了 收益105.84元

9

克里斯蒂亚诺诺 收益91.08元

10

技术-小陈 收益79.5元

请使用微信扫码

加入交流群

请使用微信扫一扫!