sudo nano DS.yml
--- - name: DS |
hosts: DS |
gather_facts: no |
|
tasks: |
- name: tao vlan |
ios_vlan: |
aggregate: |
- { vlan_id : 10 } |
- { vlan_id : 20 } |
- name: Show vlan |
ios_command: |
commands: |
- show vlan |
|
register: show_ip |
- name: config |
ios_config: |
lines: |
- spanning-tree mode rapid-pvst |
- name: chuyen cong e0/1 - e0/3 sang mode trunk |
ios_config: |
parents: |
- int range e0/1-3 |
lines: |
- sw trunk en dot1Q |
- sw mode trunk |
|
- debug: var=show_ip.stdout_lines |
--- - name: HSRP DS1 |
|
hosts: DS1 |
|
gather_facts: no |
|
|
|
tasks: |
|
- name: HSRP 10 |
|
ios_config: |
|
parents: |
|
- int vlan 10 |
|
lines: |
|
- ip address 10.1.10.252 255.255.255.0 |
|
- standby 10 ip 10.1.10.254 |
|
- standby 10 priority 150 |
|
- standby 10 preempt |
|
- ip ospf 1 area 0 |
|
- name: HSRP 20 |
|
ios_config: |
|
parents: |
|
- int vlan 20 |
|
lines: |
|
- ip address 10.1.20.252 255.255.255.0 |
|
- standby 20 ip 10.1.10.254 |
|
- standby 20 priority 150 |
|
- standby 20 preempt |
|
- ip ospf 1 area 0 |
|
- name: OSPF |
|
ios_config: |
|
parents: |
|
- router ospf 1 |
|
lines: |
|
- router-id 2.2.2.2 |
|
- name: Set interface e1/0 |
|
ios_config: |
|
parents: |
|
- int e1/0 |
|
lines: |
|
- no sw |
|
- no sh |
|
- ip address 172.16.12.2 255.255.255.0 |
--- - name: HSRP DS2 |
hosts: DS2 |
gather_facts: no |
|
tasks: |
- name: HSRP 10 |
ios_config: |
parents: |
- int vlan 10 |
lines: |
- ip address 10.1.10.253 255.255.255.0 |
- standby 10 ip 10.1.10.254 |
- standby 10 priority 100 |
- standby 10 preempt |
- ip ospf 1 area 0 |
- name: HSRP 20 |
ios_config: |
parents: |
- int vlan 20 |
lines: |
- ip address 10.1.20.253 255.255.255.0 |
- standby 20 ip 10.1.10.254 |
- standby 20 priority 100 |
- standby 20 preempt |
- ip ospf 1 area 0 |
- name: OSPF |
parents: |
- router ospf 1 |
lines: |
- router-id 3.3.3.3 |
- name: Set interface e1/0 |
ios_config: |
parents: |
- int e1/0 |
lines: |
- no sw |
- no sh |
- ip address 172.16.12.2 255.255.255.0 |
Thực hiện chạy file playbook bằng câu lệnh sau ansible-playbook
Sử dụng PC1 thuộc Vlan 10, ping tới địa chỉ IP của Switch HSRP 10.1.10.254
Và Router 172.16.12.1
Kết quả ping đến Switch HSRP:
Kết quả ping đến Router: