Skip to content

Commit 7dca20d

Browse files
docs: Add examples using network_state variable
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
1 parent e13482e commit 7dca20d

1 file changed

Lines changed: 235 additions & 0 deletions

File tree

examples/network_state_example.yml

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
---
3+
- name: Manage network using network_state
4+
hosts: network-test
5+
tasks:
6+
- name: Configure eth1 to use the IP address 192.168.1.10/24
7+
vars:
8+
network_state:
9+
interfaces:
10+
- name: eth1
11+
type: ethernet
12+
state: up
13+
ipv4:
14+
enabled: true
15+
dhcp: false
16+
address:
17+
- ip: 192.168.1.10
18+
prefix-length: 24
19+
ansible.builtin.include_role:
20+
name: linux-system-roles.network
21+
22+
- name: Delete the ethernet device eth1
23+
vars:
24+
network_state:
25+
interfaces:
26+
- name: eth1
27+
type: ethernet
28+
state: absent
29+
ansible.builtin.include_role:
30+
name: linux-system-roles.network
31+
32+
- name: Bring up the ethernet device eth1
33+
vars:
34+
network_state:
35+
interfaces:
36+
- name: eth1
37+
type: ethernet
38+
state: up
39+
ansible.builtin.include_role:
40+
name: linux-system-roles.network
41+
42+
- name: Configure the ethernet device dhcpcli with IPv6 disabled
43+
vars:
44+
network_state:
45+
interfaces:
46+
- name: dhcpcli
47+
type: ethernet
48+
state: up
49+
ipv6:
50+
enabled: false
51+
ansible.builtin.include_role:
52+
name: linux-system-roles.network
53+
54+
- name: Configure the ethernet interface eth1 with the IPv6 address
55+
2001:db8:2::1/64
56+
vars:
57+
network_state:
58+
interfaces:
59+
- name: eth1
60+
type: ethernet
61+
state: up
62+
ipv6:
63+
dhcp: false
64+
address:
65+
- ip: 2001:db8:2::1
66+
prefix-length: 64
67+
ansible.builtin.include_role:
68+
name: linux-system-roles.network
69+
70+
- name: Set the mtu of eth4 to 1500
71+
vars:
72+
network_state:
73+
interfaces:
74+
- name: eth4
75+
type: ethernet
76+
state: up
77+
mtu: 1500
78+
ansible.builtin.include_role:
79+
name: linux-system-roles.network
80+
81+
82+
- name: Configure the eth1 ethernet device with static IPv4 address
83+
192.0.2.251/24 and static IPv6 address 2001:db8:1::1/64
84+
vars:
85+
network_state:
86+
interfaces:
87+
- name: eth1
88+
type: ethernet
89+
state: up
90+
ipv4:
91+
enabled: true
92+
dhcp: false
93+
address:
94+
- ip: 192.0.2.251
95+
prefix-length: 24
96+
ipv6:
97+
enabled: true
98+
dhcp: false
99+
autoconf: false
100+
address:
101+
- ip: 2001:db8:1::1
102+
prefix-length: 64
103+
ansible.builtin.include_role:
104+
name: linux-system-roles.network
105+
106+
107+
- name: Configure bond interface bond99 with two ports eth1 and eth2, set
108+
bonding mode balance-rr
109+
vars:
110+
network_state:
111+
interfaces:
112+
- name: bond99
113+
type: bond
114+
state: up
115+
link-aggregation:
116+
mode: balance-rr
117+
port:
118+
- eth1
119+
- eth2
120+
ansible.builtin.include_role:
121+
name: linux-system-roles.network
122+
123+
- name: Set the ports config for bond99, set the port eth1 priority to -1
124+
and queue id to 1, set the port eth2 priority to 9 and queue id to 0
125+
vars:
126+
network_state:
127+
interfaces:
128+
- name: bond99
129+
type: bond
130+
state: up
131+
link-aggregation:
132+
ports-config:
133+
- name: eth1
134+
priority: -1
135+
queue-id: 1
136+
- name: eth2
137+
priority: 9
138+
queue-id: 0
139+
ansible.builtin.include_role:
140+
name: linux-system-roles.network
141+
142+
143+
- name: Set the bonding mode balance-rr and miimon value to 200 for bond99
144+
vars:
145+
network_state:
146+
interfaces:
147+
- name: bond99
148+
type: bond
149+
state: up
150+
link-aggregation:
151+
mode: balance-rr
152+
options:
153+
miimon: 200
154+
ansible.builtin.include_role:
155+
name: linux-system-roles.network
156+
157+
- name: Set the bonding mode to balance-tlb for bond device bond99
158+
vars:
159+
network_state:
160+
interfaces:
161+
- name: bond99
162+
type: bond
163+
state: up
164+
link-aggregation:
165+
mode: balance-tlb
166+
ansible.builtin.include_role:
167+
name: linux-system-roles.network
168+
169+
- name: Configure the ethernet device eth1 with dhcp4 configured
170+
vars:
171+
network_state:
172+
interfaces:
173+
- name: eth1
174+
type: ethernet
175+
state: up
176+
ipv4:
177+
enabled: true
178+
dhcp: true
179+
ansible.builtin.include_role:
180+
name: linux-system-roles.network
181+
182+
183+
- name: Set the default route to fe80::1 on eth1
184+
vars:
185+
network_state:
186+
routes:
187+
config:
188+
- destination: ::/0
189+
next-hop-interface: eth1
190+
next-hop-address: fe80::1
191+
ansible.builtin.include_role:
192+
name: linux-system-roles.network
193+
194+
- name: Configure the ethernet device eth1 with dhcp4 configured
195+
vars:
196+
network_state:
197+
interfaces:
198+
- name: eth1
199+
type: ethernet
200+
state: up
201+
ipv4:
202+
enabled: true
203+
dhcp: true
204+
ansible.builtin.include_role:
205+
name: linux-system-roles.network
206+
207+
- name: Configure the vrf interface test-vrf0 with vrf port eth1 and vrf route table 101
208+
vars:
209+
network_state:
210+
interfaces:
211+
- name: test-vrf0
212+
type: vrf
213+
state: up
214+
vrf:
215+
port:
216+
- eth1
217+
route-table-id: 101
218+
ansible.builtin.include_role:
219+
name: linux-system-roles.network
220+
221+
- name: Assign 10.255.255.1/22 to enp1s0
222+
vars:
223+
network_state:
224+
interfaces:
225+
- name: enp1s0
226+
type: ethernet
227+
state: up
228+
ipv4:
229+
enabled: true
230+
dhcp: false
231+
address:
232+
- ip: 10.255.255.1
233+
prefix-length: 22
234+
ansible.builtin.include_role:
235+
name: linux-system-roles.network

0 commit comments

Comments
 (0)