• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.
Xin chào ! Nếu đây là lần đầu tiên bạn đến với diễn đàn, xin vui lòng danh ra một phút bấm vào đây để đăng kí và tham gia thảo luận cùng VnPro.

Announcement

Collapse
No announcement yet.

Lab: Quản lý và triển khai tự động hạ tầng mạng dùng Ansible (Phần 2)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Lab: Quản lý và triển khai tự động hạ tầng mạng dùng Ansible (Phần 2)


    File cấu hình cho 2 DS (Distributed Switch):
    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

File để cấu hình thêm cho DS1 :
sudo nano DS1_HSRP.yml


---
- 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

File để cấu hình thêm cho DS2 :
sudo nano DS2_HSRP.yml


---
- 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 ios_config:
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

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:

Click image for larger version

Name:	Lab Quản lý và triển khai tự động hạ tầng mạng dùng Ansible 015.jpg
Views:	40
Size:	26.9 KB
ID:	425043
​​​​​​​
Tags:

Working...
X