Lab: Quản lý và triển khai tự động hạ tầng mạng dùng Ansible
Sơ đồ mạng:
Mô tả:
- Sơ đồ gồm 1 Router, 2 Distributed Switch, 2 Access Switch, 2 PC cho 2 Vlan, được kết nối với Ansible Server. Mô hình thực hiện trên Linux OS và các thiết bị ảo.
- Máy tính của học viên có kết nối mạng bên trong VnPro
- Thực hiện các công việc sau:
- Thêm thiết bị vào file hosts – file lưu IP các thiết bị
- Tạo playbook YAML để thực hiện các cấu hình tự động cho Router, 2 DS (Distributed Switch), 2 AS(Access Switch).
- Chạy các playbook trên.
Các bước thực hiện:
Cấu hình SSH Router
Code:
[FONT=Times New Roman][COLOR=black]R# configure terminal[/COLOR][/FONT] [FONT=Times New Roman][COLOR=black]R(config)# username admin password 123[/COLOR][/FONT] [FONT=Times New Roman][COLOR=black]R(config)# ip domain-name vnpro[/COLOR][/FONT] [FONT=Times New Roman][COLOR=black]R(config)# enable password 321[/COLOR][/FONT] [FONT=Times New Roman][COLOR=black]R(config)# crypto key generate rsa[/COLOR][/FONT] [FONT=Times New Roman][COLOR=black]1024[/COLOR][/FONT] [FONT=Times New Roman][COLOR=black]R(config)#line vty 0 4[/COLOR][/FONT] [FONT=Times New Roman][COLOR=black]R(config-line)# password 123[/COLOR][/FONT] [FONT=Times New Roman][COLOR=black]R(config-line)# login local[/COLOR][/FONT]
Code:
[FONT=Times New Roman][COLOR=black]SW# configure terminal[/COLOR][/FONT] [FONT=Times New Roman][COLOR=black]SW(config)# ip domain-name vnpro[/COLOR][/FONT] [FONT=Times New Roman][COLOR=black]SW(config)# username admin password 123[/COLOR][/FONT] [FONT=Times New Roman][COLOR=black]SW(config)# enable password 321[/COLOR][/FONT] [FONT=Times New Roman][COLOR=black]SW(config)# crypto key generate rsa[/COLOR][/FONT] [FONT=Times New Roman][COLOR=black]1024[/COLOR][/FONT] [FONT=Times New Roman][COLOR=black]SW(config)#line vty 0 4[/COLOR][/FONT] [FONT=Times New Roman][COLOR=black]SW(config-line)# password 123[/COLOR][/FONT] [FONT=Times New Roman][COLOR=black]SW(config-line)# login local[/COLOR][/FONT]
Chạy 3 dòng lệnh sau:
Code:
[FONT=Calibri][FONT=Courier New][COLOR=#323232]sudo apt-add-repository ppa:ansible/ansible[/COLOR][/FONT][/FONT] [FONT=Calibri][FONT=Courier New][COLOR=#323232]sudo apt update[/COLOR][/FONT][/FONT] [FONT=Calibri][FONT=Courier New][COLOR=#323232]sudo apt install ansible[/COLOR][/FONT][/FONT]
Code:
[FONT=Calibri][FONT=Times New Roman]cd /etc/ansible[/FONT][/FONT] [FONT=Calibri][FONT=Times New Roman]sudo nano hosts[/FONT][/FONT]
Giải thích:
- Ansible_host: địa chỉ IP của thiết bị dùng để SSH
- Ansible_become_password: là enable password của thiết bị
- Ansible_connection: network_cli là phương thức kết nối đến thiết bị thông qua SSH
- Ansible_become: ‘yes’ và ansible_become_method: enable là cho phép ansible có thể vào privilege mode trước khi thực thi các task
- Ansible_network_os: ios ở đây do dùng các thiết bị của Cisco nên khai báo như vậy
Sau khi xong nhấn Ctr + X, sau đó Y và enter để lưu file lại.
Tạo các file Playbook:
Tạo file playbook bằng câu lệnh sau: sudo nano <filename>.yml. Nên tham khảo thêm các viết file YAML
Ví dụ một số lệnh sử dụng trên thiết bị Cisco IOS để viết các nhiệm vụ trong playbook bằng ngôn ngữ YAML, chạy trên Ansible server
Ios_command: thực hiện khi thiết bị ở mode Privileged
Code:
[FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]tasks[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#404040][B]-[/B] [/COLOR][/FONT][FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]chạy lên show version[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]ios_command[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]commands[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]show version[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#404040][B]-[/B] [/COLOR][/FONT][FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]chạy lệnh show version bao gồm IOS[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]ios_command[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]commands[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]show version[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]wait_for[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]result[0] contains IOS[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#404040][B]-[/B] [/COLOR][/FONT][FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]chạy nhiều lệnh [/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]ios_command[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]commands[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#404040][B]-[/B] [/COLOR][/FONT][FONT=Times New Roman][COLOR=#032f62]show version[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#404040][B]-[/B] [/COLOR][/FONT][FONT=Times New Roman][COLOR=#032f62]show interfaces[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#404040][B]-[/B] [/COLOR][/FONT][FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]chạy lệnh yêu cầu trả lời prompt[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]ios_command[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]commands[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#404040][B]-[/B] [/COLOR][/FONT][FONT=Times New Roman][COLOR=#22863a]command[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#4070a0]'clear[/COLOR][/FONT][FONT=Times New Roman][COLOR=#4070a0]counters[/COLOR][/FONT][FONT=Times New Roman][COLOR=#4070a0]GigabitEthernet0/1'[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]prompt[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#4070a0]'Clear[/COLOR][/FONT][FONT=Times New Roman][COLOR=#4070a0]"show[/COLOR][/FONT][FONT=Times New Roman][COLOR=#4070a0]interface"[/COLOR][/FONT][FONT=Times New Roman][COLOR=#4070a0]counters[/COLOR][/FONT][FONT=Times New Roman][COLOR=#4070a0]on[/COLOR][/FONT][FONT=Times New Roman][COLOR=#4070a0]this[/COLOR][/FONT][FONT=Times New Roman][COLOR=#4070a0]interface[/COLOR][/FONT][FONT=Times New Roman][COLOR=#4070a0]\[confirm\]'[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]answer[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#4070a0]'y'[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#404040][B]-[/B] [/COLOR][/FONT][FONT=Times New Roman][COLOR=#22863a]command[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#4070a0]'clear[/COLOR][/FONT][FONT=Times New Roman][COLOR=#4070a0]counters[/COLOR][/FONT][FONT=Times New Roman][COLOR=#4070a0]GigabitEthernet0/2'[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]prompt[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#4070a0]'[confirm]'[/COLOR][/FONT][/FONT] [FONT=Times New Roman][COLOR=#22863a]answer[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#4070a0]"\r"[/COLOR][/FONT]
Code:
[FONT=Courier New][B][FONT=Times New Roman][COLOR=#404040]-[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]cấu hình hostname trong inventory[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]ios_config[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]lines[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]hostname[/COLOR][/FONT] [FONT=Times New Roman][COLOR=#007020]{{[/COLOR][/FONT] [B][FONT=Times New Roman][COLOR=#9960b5]inventory_hostname[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#007020]}}[/COLOR][/FONT][/FONT] [FONT=Courier New][B][FONT=Times New Roman][COLOR=#404040]-[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]cấu hình cổng[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]ios_config[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]lines[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#404040][B]-[/B] [/COLOR][/FONT][FONT=Times New Roman][COLOR=#032f62]description test interface[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#404040][B]-[/B] [/COLOR][/FONT][FONT=Times New Roman][COLOR=#032f62]ip address 172.31.1.1 255.255.255.0[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]parents[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]interface Ethernet1[/COLOR][/FONT][/FONT] [FONT=Courier New][B][FONT=Times New Roman][COLOR=#404040]-[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]cấu hình ip helper-address trên nhiều cổng[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]ios_config[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]lines[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#404040][B]-[/B] [/COLOR][/FONT][FONT=Times New Roman][COLOR=#032f62]ip helper-address 172.26.1.10[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#404040][B]-[/B] [/COLOR][/FONT][FONT=Times New Roman][COLOR=#032f62]ip helper-address 172.26.3.8[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]parents[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#4070a0]"[/COLOR][/FONT][FONT=Times New Roman][COLOR=#007020]{{[/COLOR][/FONT] [B][FONT=Times New Roman][COLOR=#9960b5]item[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#007020]}}[/COLOR][/FONT][FONT=Times New Roman][COLOR=#4070a0]"[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]with_items[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#404040][B]-[/B] [/COLOR][/FONT][FONT=Times New Roman][COLOR=#032f62]interface Ethernet1[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#404040][B]-[/B] [/COLOR][/FONT][FONT=Times New Roman][COLOR=#032f62]interface Ethernet2[/COLOR][/FONT][/FONT][FONT=Times New Roman][COLOR=#404040] [B]-[/B] [/COLOR][/FONT][FONT=Times New Roman][COLOR=#032f62]interface GigabitEthernet1[/COLOR][/FONT]
Code:
[FONT=Courier New][B][FONT=Times New Roman][COLOR=#404040]-[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]cấu hình cổng[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]ios_interface[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]GigabitEthernet0/2[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]description[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]test-interface[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]speed[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]100[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]duplex[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]half[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]mtu[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]512[/COLOR][/FONT][/FONT] [FONT=Courier New][B][FONT=Times New Roman][COLOR=#404040]-[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]xóa cổng looback[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]ios_interface[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]Loopback9[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]state[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]absent[/COLOR][/FONT][/FONT] [FONT=Courier New][B][FONT=Times New Roman][COLOR=#404040]-[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]mở cổng(up)[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]ios_interface[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]GigabitEthernet0/2[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]enabled[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]True[/COLOR][/FONT][/FONT] [FONT=Courier New][B][FONT=Times New Roman][COLOR=#404040]-[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]tắt cổng(down)[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]ios_interface[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]GigabitEthernet0/2[/COLOR][/FONT][/FONT] [FONT=Times New Roman][COLOR=#22863a]enabled[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]False[/COLOR][/FONT]
Code:
[FONT=Courier New][B][FONT=Times New Roman][COLOR=#404040]-[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]Tạo vlan[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]ios_vlan[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]vlan_id[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]100[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]test-vlan[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]state[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]present[/COLOR][/FONT][/FONT] [FONT=Courier New][B][FONT=Times New Roman][COLOR=#404040]-[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]Thêm cổng vào vlan[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]ios_vlan[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]vlan_id[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]100[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]interfaces[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#404040][B]-[/B] [/COLOR][/FONT][FONT=Times New Roman][COLOR=#032f62]GigabitEthernet0/0[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#404040][B]-[/B] [/COLOR][/FONT][FONT=Times New Roman][COLOR=#032f62]GigabitEthernet0/1[/COLOR][/FONT][/FONT] [FONT=Courier New][B][FONT=Times New Roman][COLOR=#404040]-[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]Xóa vlan[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]ios_vlan[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]vlan_id[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]100[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]state[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]absent[/COLOR][/FONT][/FONT] [FONT=Courier New][B][FONT=Times New Roman][COLOR=#404040]-[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#22863a]name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [FONT=Times New Roman][COLOR=#032f62]Thêm vlan dùng aggregate[/COLOR][/FONT][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]ios_vlan[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#22863a]aggregate[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][/FONT] [FONT=Courier New][FONT=Times New Roman][COLOR=#404040][B]-[/B] [B]{[/B][/COLOR][/FONT][FONT=Times New Roman][COLOR=#22863a] vlan_id[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [B][FONT=Times New Roman][COLOR=#9960b5]100[/COLOR][/FONT][/B][B][FONT=Times New Roman][COLOR=#404040],[/COLOR][/FONT][/B][FONT=Times New Roman][COLOR=#22863a] name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [B][FONT=Times New Roman][COLOR=#9960b5]test-vlan[/COLOR][/FONT][/B][B][FONT=Times New Roman][COLOR=#404040],[/COLOR][/FONT][/B][FONT=Times New Roman][COLOR=#22863a] interfaces[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B][FONT=Times New Roman][COLOR=#404040] [B][[/B][/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#9960b5]GigabitEthernet0/1[/COLOR][/FONT][/B][B][FONT=Times New Roman][COLOR=#404040],[/COLOR][/FONT][/B] [B][FONT=Times New Roman][COLOR=#9960b5]GigabitEthernet0/2[/COLOR][/FONT][/B][B][FONT=Times New Roman][COLOR=#404040]],[/COLOR][/FONT][/B][FONT=Times New Roman][COLOR=#22863a] delay[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [B][FONT=Times New Roman][COLOR=#9960b5]15[/COLOR][/FONT][/B][B][FONT=Times New Roman][COLOR=#404040],[/COLOR][/FONT][/B][FONT=Times New Roman][COLOR=#22863a] state[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [B][FONT=Times New Roman][COLOR=#9960b5]suspend[/COLOR][/FONT][/B][FONT=Times New Roman][COLOR=#404040] [B]}[/B][/COLOR][/FONT][/FONT] [FONT=Times New Roman][COLOR=#404040]- [B]{[/B][/COLOR][/FONT][FONT=Times New Roman][COLOR=#22863a] vlan_id[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [B][FONT=Times New Roman][COLOR=#9960b5]101[/COLOR][/FONT][/B][B][FONT=Times New Roman][COLOR=#404040],[/COLOR][/FONT][/B][FONT=Times New Roman][COLOR=#22863a] name[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [B][FONT=Times New Roman][COLOR=#9960b5]test-vlan[/COLOR][/FONT][/B][B][FONT=Times New Roman][COLOR=#404040],[/COLOR][/FONT][/B][FONT=Times New Roman][COLOR=#22863a] interfaces[/COLOR][/FONT][B][FONT=Times New Roman][COLOR=#404040]:[/COLOR][/FONT][/B] [B][FONT=Times New Roman][COLOR=#9960b5]GigabitEthernet0/3[/COLOR][/FONT][/B][FONT=Times New Roman][COLOR=#404040] [B]}[/B][/COLOR][/FONT]
Chạy các playbook:
Thực hiện chạy file playbook bằng câu lệnh sau ansible-playbook <filename>
ansible-playbook AS.yml
ansible-playbook DS.yml
ansible-playbook DS1_HSRP.yml
ansible-playbook DS2_HSRP.yml
ansible-playbook R.yml
Kiểm tra:
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: