为交换机S1、S2、S3分别创建VLAN、并进行Access接口的配置,同时对所有交换机进行Trunk接口的全局自动配置。
所有Switches的脚本合并:SwitchesConfig.yml
---
- name: Switches Global Configurationhosts: Switchesgather_facts: falseconnection: network_clitasks:- name: Interface Trunk Configios_config:parents: "interface FastEthernet1/0"lines:- switchport trunk encapsulation dot1q- switchport mode trunk register: print_output- debug: var=print_output- name: S1 Configurationhosts: S1gather_facts: falseconnection: network_clitasks:- name: Vlan Configios_command:commands:- vlan database- vlan 10- vlan 20- vlan 30- exitregister: print_output- debug: var=print_output- name: Interface Acces Configios_config:parents: "interface {{ item.interface }}"lines:- switchport mode access- "switchport access vlan {{ item.vlan }}"with_items:- { interface : FastEthernet1/1, vlan : 10 }- { interface : FastEthernet1/2, vlan : 20 }- { interface : FastEthernet1/3, vlan : 30 }register: print_output- debug: var=print_output- name: S2 Configurationhosts: S2gather_facts: falseconnection: network_clitasks:- name: Vlan Configios_command:commands:- vlan database- vlan 40- vlan 50- vlan 60- exitregister: print_output- debug: var=print_output- name: Interface Acces Configios_config:parents: "interface {{ item.interface }}"lines:- switchport mode access- "switchport access vlan {{ item.vlan }}"with_items:- { interface : FastEthernet1/1, vlan : 40 }- { interface : FastEthernet1/2, vlan : 50 }- { interface : FastEthernet1/3, vlan : 60 }register: print_output- debug: var=print_output- name: S3 Configurationhosts: S3gather_facts: falseconnection: network_clitasks:- name: Vlan Configios_command:commands:- vlan database- vlan 70- vlan 80- exitregister: print_output- debug: var=print_output- name: Interface Acces Configios_config:parents: "interface {{ item.interface }}"lines:- switchport mode access- "switchport access vlan {{ item.vlan }}"with_items:- { interface : FastEthernet1/1, vlan : 70 }- { interface : FastEthernet1/2, vlan : 80 }register: print_output- debug: var=print_output