(测试成功)
- ---
- - name: Routers Configuration
- hosts: R1
- gather_facts: false
- connection: network_cli
-
- tasks:
- - name: DHCP Config
- ios_config:
- parents: "ip dhcp pool Reception"
- lines:
- - network 192.168.10.0 255.255.255.0
- - default-router 192.168.10.1
- - dns-server 192.168.10.1
-
- register: print_output
-
- - debug: var=print_output
(测试成功)
- ---
- - name: Routers Configuration
- hosts: R1
- gather_facts: false
- connection: network_cli
-
- tasks:
- - name: DHCP Config
- ios_config:
- parents: "ip dhcp pool {{ item.pool }}"
- lines:
- - "network {{ item.network }} 255.255.255.0"
- - "default-router {{ item.def_dns }}"
- - "dns-server {{ item.def_dns }}"
- with_items:
- - { pool : Reception, network : 192.168.10.0, def_dns : 192.168.10.1 }
-
- register: print_output
-
- - debug: var=print_output
(测试成功)
- ---
- - name: Routers Configuration
- hosts: R1
- gather_facts: false
- connection: network_cli
-
- tasks:
- - name: DHCP Config
- ios_config:
- parents: "ip dhcp pool {{ item.pool }}"
- lines:
- - "network {{ item.network }} 255.255.255.0"
- - "default-router {{ item.def_dns }}"
- - "dns-server {{ item.def_dns }}"
- with_items:
- - { pool : Reception, network : 192.168.10.0, def_dns : 192.168.10.1 }
- - { pool : Store, network : 192.168.20.0, def_dns : 192.168.20.1 }
- - { pool : Logistics, network : 192.168.30.0, def_dns : 192.168.30.1 }
-
- register: print_output
-
- - debug: var=print_output
(测试成功)
- ---
- - name: Routers Configuration
- hosts: R1
- gather_facts: false
- connection: network_cli
-
- tasks:
- - name: R1 OSPF Config
- ios_config:
- parents: "router ospf 10"
- lines:
- - network 192.168.10.0 0.0.0.255 area 0
- - network 192.168.20.0 0.0.0.255 area 0
- - network 192.168.30.0 0.0.0.255 area 0
-
- register: print_output
-
- - debug: var=print_output
(OSPF与DHCP脚本合并,测试成功)
- ---
- - name: R1 Configuration
- hosts: R1
- gather_facts: false
- connection: network_cli
-
- tasks:
- - name: DHCP Config
- ios_config:
- parents: "ip dhcp pool {{ item.pool }}"
- lines:
- - "network {{ item.network }} 255.255.255.0"
- - "default-router {{ item.def_dns }}"
- - "dns-server {{ item.def_dns }}"
- with_items:
- - { pool : Reception, network : 192.168.10.0, def_dns : 192.168.10.1 }
- - { pool : Store, network : 192.168.20.0, def_dns : 192.168.20.1 }
- - { pool : Logistics, network : 192.168.30.0, def_dns : 192.168.30.1 }
-
- register: print_output
-
- - debug: var=print_output
-
-
-
- - name: R1 OSPF Config
- ios_config:
- parents: "router ospf 10"
- lines:
- - network 192.168.10.0 0.0.0.255 area 0
- - network 192.168.20.0 0.0.0.255 area 0
- - network 192.168.30.0 0.0.0.255 area 0
-
- register: print_output
-
- - debug: var=print_output
(R1的接口、DHCP、OSPF配置合并,测试成功)
- ---
- - name: R1 Configuration
- hosts: R1
- gather_facts: false
- connection: network_cli
-
- tasks:
- - name: Interface Config
- ios_config:
- parents: "interface {{ item.interface }}"
- lines:
- - "encapsulation dot1Q {{ item.vlan }}"
- - "ip address {{ item.address }} 255.255.255.0"
- with_items:
- - { interface : FastEthernet2/0.10, vlan : 10, address : 192.168.10.1 }
- - { interface : FastEthernet2/0.20, vlan : 20, address : 192.168.20.1 }
- - { interface : FastEthernet2/0.30, vlan : 30, address : 192.168.30.1 }
-
- register: print_output
-
- - debug: var=print_output
-
-
-
- - name: DHCP Config
- ios_config:
- parents: "ip dhcp pool {{ item.pool }}"
- lines:
- - "network {{ item.network }} 255.255.255.0"
- - "default-router {{ item.def_dns }}"
- - "dns-server {{ item.def_dns }}"
- with_items:
- - { pool : Reception, network : 192.168.10.0, def_dns : 192.168.10.1 }
- - { pool : Store, network : 192.168.20.0, def_dns : 192.168.20.1 }
- - { pool : Logistics, network : 192.168.30.0, def_dns : 192.168.30.1 }
-
- register: print_output
-
- - debug: var=print_output
-
-
-
- - name: OSPF Config
- ios_config:
- parents: "router ospf 10"
- lines:
- - network 192.168.10.0 0.0.0.255 area 0
- - network 192.168.20.0 0.0.0.255 area 0
- - network 192.168.30.0 0.0.0.255 area 0
-
- register: print_output
-
- - debug: var=print_output