ansible 批量配置cisco 交换机---接口篇
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,关于ansible不做介绍。本例主要通过实例介绍ansible配置ios接口的几种方法,或者说可利用哪些模块配置接口。1 .主机列表,本次测试以1台主机为例[root@Ansible-01 ansib
千家信息网最后更新 2026年11月01日ansible 批量配置cisco 交换机---接口篇
关于ansible不做介绍。
本例主要通过实例介绍ansible配置ios接口的几种方法,或者说可利用哪些模块配置接口。
1 .主机列表,本次测试以1台主机为例
[root@Ansible-01 ansible]# cat hosts[cisco]172.16.254.130 ansible_connection=local 2.playbooks内容
[root@Ansible-01 interface]# cat interface-phy.yml ---- name: interface config hosts: cisco # vars: # creds: # username: "{{ username }}" # password: "{{ password }}" gather_facts: no tasks: - name: action interface G1-2 configure ios_config: lines: - no shutdown - switch mode trunk - switch trunk allow vlan all - do wr parents: interface range gigabitEthernet 1/0/1 - 2 - name: action interface G3 configuration ios_l2_interface: name: GigabitEthernet1/0/3 mode: access access_vlan: 100 - name: action interface G3 configuration ios_l2_interface: name: GigabitEthernet1/0/4 mode: trunk native_vlan: 100 trunk_allowed_vlans: 10-255 - name: save configuration ios_command: commands: - wr3.执行playbooks
[root@Ansible-01 interface]# ansible-playbook interface-phy.yml -u admin -k SSH password: PLAY [interface config] **************************************************************************************************************TASK [action interface G1-2 configure] ***********************************************************************************************changed: [172.16.254.130]TASK [action interface G3 configuration] *********************************************************************************************changed: [172.16.254.130]TASK [action interface G4 configuration] *********************************************************************************************changed: [172.16.254.130]TASK [save configuration] ************************************************************************************************************ok: [172.16.254.130]PLAY RECAP ***************************************************************************************************************************172.16.254.130 : ok=4 changed=3 unreachable=0 failed=0 4.查看执行效果
interface GigabitEthernet1/0/1 switchport mode trunk!interface GigabitEthernet1/0/2 switchport mode trunk!interface GigabitEthernet1/0/3 switchport access vlan 100 switchport mode access!interface GigabitEthernet1/0/4 switchport trunk native vlan 100 switchport trunk allowed vlan 10-255 switchport mode trunk!- 可见 ios_config和 ios_l2_interface 两个模块都可以操作,只有三层接口则可以使用ios_comfig或者ios_l3_interface模块。
接口
模块
配置
主机
两个
内容
只有
实例
效果
方法
测试
交换机
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
耶加雪菲
广州大一互联网络科技有限公司
互联网属科技
互联网科技美容
互联网科技有限公司 翻译
恒生科技互联网指数分析
汉立互联网科技有限公司联系电话
阿里巴巴算科技企业还是互联网
昭通云南众福互联网科技有限公司
科技互联网大厂
开一家科技互联网公司需要多少钱
互联网公司高科技产品
电子商务与互联网科技的关系
本届互联网大会上的黑科技
广州有谷有贝互联网科技有限公司
互联网科技手机排行榜
数字互联网科技有限公司
杭州科技互联网公司有哪些
上海旺乐尼互联网科技有限公司
科技发展第三阶段互联网时代
咖啡网
什么是科技互联网
汇久创客互联网科技
互联网科技小额贷款
杭州壁岐互联网科技有限公司
玉溪新华互联网科技好不好
广州富喜互联网络科技
神州科技互联网有限公司
萌小萌互联网科技河南有限公司
中国主要互联网科技公司