15
15
description:
16
16
- Create/Update/Delete proxmox sdn zones.
17
17
author: 'Jana Hoch <[email protected] > (!UNKNOWN)'
18
+ version_added: "1.4.0"
18
19
attributes:
19
20
check_mode:
20
21
support: none
21
22
diff_mode:
22
23
support: none
23
24
options:
24
- state :
25
- description:
26
- - The desired state of the zone configuration .
27
- type: str
28
- choices :
29
- - present
30
- - absent
31
- default: present
32
- update :
33
- description:
34
- - If O(state=present) and zone exists it'll update .
35
- type: bool
36
- default: true
37
- type :
38
- description:
39
- - Specify the type of zone.
40
- type: str
41
- choices :
42
- - evpn
43
- - faucet
44
- - qinq
45
- - simple
46
- - vlan
47
- - vxlan
48
- zone:
49
- description:
50
- - Unique zone name.
51
- type: str
52
- advertise_subnets:
53
- description:
54
- - Advertise evpn subnets if you have silent hosts.
55
- type: bool
56
- bridge:
57
- description:
58
- - Specify the bridge interface to use.
59
- type: str
60
- bridge_disable_mac_learning:
61
- description:
62
- - Disable auto MAC address learning on the bridge interface.
63
- type: bool
64
- controller:
65
- description:
66
- - Frr router name.
67
- type: str
68
- dhcp:
69
- description:
70
- - Type of the DHCP backend for this zone.
71
- type: str
72
- choices:
73
- - dnsmasq
74
- disable_arp_nd_suppression :
75
- description:
76
- - Disable ipv4 arp && ipv6 neighbour discovery suppression .
77
- type: bool
78
- dns :
79
- description:
80
- - DNS api server .
81
- type: str
82
- dnszone :
83
- description:
84
- - DNS domain zone .
85
- type: str
86
- dp_id :
87
- description:
88
- - Faucet dataplane id .
89
- type: int
90
- exitnodes :
91
- description:
92
- - List of cluster node names.
93
- type: str
94
- exitnodes_local_routing :
95
- description:
96
- - Allow exitnodes to connect to evpn guests .
97
- type: bool
98
- exitnodes_primary :
99
- description:
100
- - Force traffic to this exitnode first .
101
- type: str
102
- fabric :
103
- description:
104
- - SDN fabric to use as underlay for this VXLAN zone .
105
- type: str
106
- ipam :
107
- description:
108
- - Use a specific ipam .
109
- type: str
110
- mac :
111
- description:
112
- - Anycast logical router mac address.
113
- type: str
114
- mtu :
115
- description:
116
- - Set the Maximum Transmission Unit (MTU) .
117
- type: int
118
- nodes :
119
- description:
120
- - List of cluster node names .
121
- type: str
122
- peers :
123
- description:
124
- - peers address list.
125
- type: str
126
- reversedns:
127
- description:
128
- - reverse dns api server
129
- type: str
130
- rt_import :
131
- description:
132
- - Route-Target import.
133
- type: str
134
- tag :
135
- description:
136
- - Service- VLAN Tag .
137
- type: int
138
- vlan_protocol :
139
- description:
140
- - Specify the VLAN protocol to use.
141
- type: str
142
- choices :
143
- - 802.1q
144
- - 802.1ad
145
- vrf_vxlan :
146
- description:
147
- - Specify the VRF VXLAN identifier .
148
- type: int
149
- vxlan_port :
150
- description:
151
- - Vxlan tunnel udp port (default 4789) .
152
- type: int
25
+ advertise_subnets :
26
+ description:
27
+ - Advertise EVPN subnets if you have silent hosts .
28
+ type: bool
29
+ bridge :
30
+ description:
31
+ - Specify the bridge interface to use.
32
+ type: str
33
+ bridge_disable_mac_learning :
34
+ description:
35
+ - Disable auto MAC address learning on the bridge interface .
36
+ type: bool
37
+ controller:
38
+ description :
39
+ - FRR router name.
40
+ type: str
41
+ dhcp:
42
+ description :
43
+ - Type of the DHCP backend for this zone.
44
+ type: str
45
+ choices:
46
+ - dnsmasq
47
+ disable_arp_nd_suppression:
48
+ description:
49
+ - Disable IPv4 ARP and IPv6 neighbour discovery suppression.
50
+ type: bool
51
+ dns:
52
+ description:
53
+ - DNS API server.
54
+ type: str
55
+ dnszone:
56
+ description:
57
+ - DNS domain zone.
58
+ type: str
59
+ dp_id:
60
+ description:
61
+ - Faucet dataplane ID.
62
+ type: int
63
+ exitnodes:
64
+ description:
65
+ - List of cluster node names.
66
+ type: str
67
+ exitnodes_local_routing:
68
+ description:
69
+ - Allow exitnodes to connect to EVPN guests.
70
+ type: bool
71
+ exitnodes_primary:
72
+ description:
73
+ - Force traffic to this exit node first.
74
+ type: str
75
+ fabric :
76
+ description:
77
+ - SDN fabric to use as underlay for this VXLAN zone .
78
+ type: str
79
+ ipam :
80
+ description:
81
+ - Use a specific IPAM .
82
+ type: str
83
+ mac :
84
+ description:
85
+ - Anycast logical router MAC address .
86
+ type: str
87
+ mtu :
88
+ description:
89
+ - Set the Maximum Transmission Unit (MTU) .
90
+ type: int
91
+ nodes :
92
+ description:
93
+ - List of cluster node names.
94
+ type: str
95
+ peers :
96
+ description:
97
+ - Peers address list .
98
+ type: str
99
+ reversedns :
100
+ description:
101
+ - Reverse DNS API server .
102
+ type: str
103
+ rt_import :
104
+ description:
105
+ - Route-Target import .
106
+ type: str
107
+ state :
108
+ description:
109
+ - The desired state of the zone configuration .
110
+ type: str
111
+ choices :
112
+ - present
113
+ - absent
114
+ default: present
115
+ tag :
116
+ description:
117
+ - Service-VLAN tag .
118
+ type: int
119
+ type :
120
+ description:
121
+ - Specify the type of zone .
122
+ type: str
123
+ choices :
124
+ - evpn
125
+ - faucet
126
+ - qinq
127
+ - simple
128
+ - vlan
129
+ - vxlan
130
+ update:
131
+ description :
132
+ - If O(state=present) and zone exists it'll update.
133
+ type: bool
134
+ default: true
135
+ vlan_protocol :
136
+ description:
137
+ - Specify the VLAN protocol to use .
138
+ type: str
139
+ choices :
140
+ - 802.1q
141
+ - 802.1ad
142
+ vrf_vxlan:
143
+ description :
144
+ - Specify the VRF VXLAN identifier.
145
+ type: int
146
+ vxlan_port :
147
+ description:
148
+ - VXLAN tunnel UDP port (default 4789) .
149
+ type: int
150
+ zone :
151
+ description:
152
+ - Unique zone name .
153
+ type: str
153
154
extends_documentation_fragment:
154
155
- community.proxmox.proxmox.actiongroup_proxmox
155
156
- community.proxmox.proxmox.documentation
156
157
- community.proxmox.attributes
157
158
"""
158
159
159
160
EXAMPLES = r"""
160
- - name: create a simple zones
161
+ - name: Create a simple zone
161
162
community.proxmox.proxmox_zone:
162
163
api_user: "root@pam"
163
164
api_password: "{{ vault.proxmox.root_password }}"
164
165
api_host: "{{ pc.proxmox.api_host }}"
165
- validate_certs: no
166
+ validate_certs: false
166
167
type: simple
167
168
zone: ansible
168
169
state: present
169
170
170
- - name: create a vlan zones
171
+ - name: Create a vlan zone
171
172
community.proxmox.proxmox_zone:
172
173
api_user: "root@pam"
173
174
api_password: "{{ vault.proxmox.root_password }}"
174
175
api_host: "{{ pc.proxmox.api_host }}"
175
- validate_certs: no
176
+ validate_certs: false
176
177
type: vlan
177
178
zone: ansible
178
179
state: present
179
180
bridge: vmbr0
180
181
181
- - name: Delete a zones
182
+ - name: Delete a zone
182
183
community.proxmox.proxmox_zone:
183
184
api_user: "root@pam"
184
185
api_password: "{{ vault.proxmox.root_password }}"
185
186
api_host: "{{ pc.proxmox.api_host }}"
186
- validate_certs: no
187
+ validate_certs: false
187
188
type: simple
188
189
zone: ansible
189
190
state: absent
@@ -337,34 +338,32 @@ def zone_present(self, update, **kwargs):
337
338
zone_type = kwargs .get ("type" )
338
339
339
340
# Check if zone already exists
341
+ if zone_name in available_zones .keys () and not update :
342
+ self .module .exit_json (
343
+ changed = False , zone = zone_name , msg = f'Zone { zone_name } already exists and update is false!'
344
+ )
340
345
if zone_name in available_zones .keys () and update :
341
346
if zone_type != available_zones [zone_name ]['type' ]:
342
347
self .module .fail_json (
343
348
msg = f'zone { zone_name } exists with different type and we cannot change type post fact.'
344
349
)
345
- else :
346
- try :
347
- kwargs ['lock-token' ] = self .get_global_sdn_lock ()
348
- kwargs ['digest' ] = available_zones [zone_name ]['digest' ]
349
- del kwargs ['zone' ]
350
- del kwargs ['type' ]
351
-
352
- zone = getattr (self .proxmox_api .cluster ().sdn ().zones (), zone_name )
353
- zone .put (** kwargs )
354
- self .apply_sdn_changes_and_release_lock (kwargs ['lock-token' ])
355
- self .module .exit_json (
356
- changed = True , zone = zone_name , msg = f'Updated zone - { zone_name } '
357
- )
358
- except Exception as e :
359
- self .rollback_sdn_changes_and_release_lock (kwargs ['lock-token' ])
360
- self .module .fail_json (
361
- msg = f'Failed to update zone { zone_name } - { e } '
362
- )
363
-
364
- elif zone_name in available_zones .keys () and not update :
365
- self .module .exit_json (
366
- changed = False , zone = zone_name , msg = f'Zone { zone_name } already exists and update is false!'
367
- )
350
+ try :
351
+ kwargs ['lock-token' ] = self .get_global_sdn_lock ()
352
+ kwargs ['digest' ] = available_zones [zone_name ]['digest' ]
353
+ del kwargs ['zone' ]
354
+ del kwargs ['type' ]
355
+
356
+ self .proxmox_api .cluster ().sdn ().zones (zone_name ).put (** kwargs )
357
+ self .apply_sdn_changes_and_release_lock (kwargs ['lock-token' ])
358
+ self .module .exit_json (
359
+ changed = True , zone = zone_name , msg = f'Updated zone - { zone_name } '
360
+ )
361
+ except Exception as e :
362
+ self .rollback_sdn_changes_and_release_lock (kwargs ['lock-token' ])
363
+ self .module .fail_json (
364
+ msg = f'Failed to update zone { zone_name } - { e } '
365
+ )
366
+ # Zone does not exist and gets created
368
367
else :
369
368
try :
370
369
kwargs ['lock-token' ] = self .get_global_sdn_lock ()
@@ -384,19 +383,17 @@ def zone_absent(self, zone_name, lock=None):
384
383
available_zones = [x .get ('zone' ) for x in self .get_zones ()]
385
384
params = {'lock-token' : lock }
386
385
386
+ if zone_name not in available_zones :
387
+ self .module .exit_json (
388
+ changed = False , zone = zone_name , msg = f"zone { zone_name } is absent."
389
+ )
387
390
try :
388
- if zone_name not in available_zones :
389
- self .module .exit_json (
390
- changed = False , zone = zone_name , msg = f"zone { zone_name } is absent."
391
- )
392
- else :
393
- params ['lock-token' ] = self .get_global_sdn_lock ()
394
- zone = getattr (self .proxmox_api .cluster ().sdn ().zones (), zone_name )
395
- zone .delete (** params )
396
- self .apply_sdn_changes_and_release_lock (params ['lock-token' ])
397
- self .module .exit_json (
398
- changed = True , zone = zone_name , msg = f'Successfully deleted zone { zone_name } '
399
- )
391
+ params ['lock-token' ] = self .get_global_sdn_lock ()
392
+ self .proxmox_api .cluster ().sdn ().zones (zone_name ).delete (** params )
393
+ self .apply_sdn_changes_and_release_lock (params ['lock-token' ])
394
+ self .module .exit_json (
395
+ changed = True , zone = zone_name , msg = f'Successfully deleted zone { zone_name } '
396
+ )
400
397
except Exception as e :
401
398
self .rollback_sdn_changes_and_release_lock (params ['lock-token' ])
402
399
self .module .fail_json (
0 commit comments