Skip to content

Commit 29e1ebf

Browse files
author
“dsoper2”
committed
vNIC template example with derive and update
1 parent fa0601d commit 29e1ebf

File tree

1 file changed

+173
-0
lines changed

1 file changed

+173
-0
lines changed
+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
---
2+
#
3+
# Configure vNIC Templates
4+
#
5+
- name: "Configure vNIC Template"
6+
hosts: localhost
7+
connection: local
8+
gather_facts: false
9+
vars:
10+
# Create an anchor for api_info that can be used throughout the file
11+
api_info: &api_info
12+
# if api_key vars are omitted, INTERSIGHT_API_KEY_ID, INTERSIGHT_API_PRIVATE_KEY,
13+
# and INTERSIGHT_API_URI environment variables used for API key data
14+
api_private_key: "{{ api_private_key | default(omit) }}"
15+
api_key_id: "{{ api_key_id | default(omit) }}"
16+
api_uri: "{{ api_uri | default(omit) }}"
17+
validate_certs: "{{ validate_certs | default(omit) }}"
18+
state: "{{ state | default(omit) }}"
19+
# vNIC Template name
20+
template_name: vnic-devnet
21+
org_name: Demo-DevNet
22+
mac_pool: DevNet-MACPool
23+
network_group: DevNet-Eth-Net-Group
24+
network_control_policy: DevNet-Eth-Net-Control
25+
qos_policy: DevNet-Eth-QoS
26+
ethernet_adapter: DevNet-EthAdapter-Windows
27+
lan_connectivity_policy: DevNet-LAN_CLONE
28+
vnic_name: vnic0-mgmt
29+
tasks:
30+
# Get the Organization Moid
31+
- name: "Get Organization Moid"
32+
cisco.intersight.intersight_rest_api:
33+
<<: *api_info
34+
resource_path: /organization/Organizations
35+
query_params:
36+
$filter: "Name eq '{{ org_name }}'"
37+
register: org_resp
38+
- name: "Get MAC Pool Moid"
39+
cisco.intersight.intersight_rest_api:
40+
<<: *api_info
41+
resource_path: /macpool/Pools
42+
query_params:
43+
$filter: "Name eq '{{ mac_pool }}'"
44+
register: mac_resp
45+
- name: "Get Network Group Moid"
46+
cisco.intersight.intersight_rest_api:
47+
<<: *api_info
48+
resource_path: /fabric/EthNetworkGroupPolicies
49+
query_params:
50+
$filter: "Name eq '{{ network_group }}'"
51+
register: network_resp
52+
- name: "Get Network Control Policy Moid"
53+
cisco.intersight.intersight_rest_api:
54+
<<: *api_info
55+
resource_path: /fabric/EthNetworkControlPolicies
56+
query_params:
57+
$filter: "Name eq '{{ network_control_policy }}'"
58+
register: control_resp
59+
- name: "Get QoS Policy Moid"
60+
cisco.intersight.intersight_rest_api:
61+
<<: *api_info
62+
resource_path: /vnic/EthQosPolicies
63+
query_params:
64+
$filter: "Name eq '{{ qos_policy }}'"
65+
register: qos_resp
66+
- name: "Get Ethernet Adapter Moid"
67+
cisco.intersight.intersight_rest_api:
68+
<<: *api_info
69+
resource_path: /vnic/EthAdapterPolicies
70+
query_params:
71+
$filter: "Name eq '{{ ethernet_adapter }}'"
72+
register: adapter_resp
73+
# Config vNIC Template
74+
- name: "Configure vNIC Template"
75+
cisco.intersight.intersight_rest_api:
76+
<<: *api_info
77+
resource_path: /vnic/VnicTemplates
78+
# method: POST
79+
query_params:
80+
$filter: "Name eq '{{ template_name }}'"
81+
api_body: {
82+
"Name": "{{ template_name }}",
83+
"Organization": {
84+
"Moid": "{{ org_resp.api_response.Moid }}"
85+
},
86+
"Cdn": {
87+
"Source": "vnic"
88+
},
89+
"EnableOverride": false,
90+
"EthAdapterPolicy": {
91+
"Moid": "{{ adapter_resp.api_response.Moid }}"
92+
},
93+
"EthQosPolicy": {
94+
"Moid": "{{ qos_resp.api_response.Moid }}"
95+
},
96+
"FabricEthNetworkControlPolicy": {
97+
"Moid": "{{ control_resp.api_response.Moid }}"
98+
},
99+
"FabricEthNetworkGroupPolicy": [
100+
{
101+
"Moid": "{{ network_resp.api_response.Moid }}"
102+
}
103+
],
104+
"FailoverEnabled": false,
105+
"MacPool": {
106+
"Moid": "{{ mac_resp.api_response.Moid }}"
107+
},
108+
"SwitchId": "A"
109+
}
110+
register: template_resp
111+
# Check if vNIC exists
112+
- name: "Get {{ vnic_name }} Moid"
113+
intersight_rest_api:
114+
resource_path: /vnic/EthIfs
115+
query_params:
116+
$filter: "Name eq '{{ vnic_name }}'"
117+
register: vnic_resp
118+
# Get LAN Connectivity Policy Moid
119+
- name: "Get LAN Connectivity Policy Moid"
120+
intersight_rest_api:
121+
resource_path: /vnic/LanConnectivityPolicies
122+
query_params:
123+
$filter: "Name eq '{{ lan_connectivity_policy }}'"
124+
register: lan_resp
125+
# Derive profiles from template (if profiles don't already exist)
126+
- name: "POST to derive {{ vnic_name }}"
127+
intersight_rest_api:
128+
resource_path: /bulk/MoCloners
129+
update_method: post
130+
api_body: {
131+
"Organization": {
132+
"Moid": "{{ org_resp.api_response.Moid }}"
133+
},
134+
"Sources": [
135+
{
136+
"ClassId": "mo.MoRef",
137+
"ObjectType": "vnic.VnicTemplate",
138+
"Moid": "{{ template_resp.api_response.Moid }}"
139+
}
140+
],
141+
"Targets": [
142+
{
143+
"Name": "{{ vnic_name }}",
144+
"LanConnectivityPolicy": "{{ lan_resp.api_response.Moid }}",
145+
"MacAddressType": "POOL",
146+
"ObjectType": "vnic.EthIf",
147+
"Placement": {},
148+
"ClassId": "vnic.EthIf"
149+
}
150+
]
151+
}
152+
when: vnic_resp.api_response is not defined or not vnic_resp.api_response
153+
# POST updates to derived profiles if template was changed
154+
- name: "POST to update {{ vnic_name }}"
155+
intersight_rest_api:
156+
resource_path: /bulk/MoMergers
157+
update_method: post
158+
api_body: {
159+
"Sources": [
160+
{
161+
"ObjectType": "vnic.VnicTemplate",
162+
"Moid": "{{ template_resp.api_response.Moid }}"
163+
}
164+
],
165+
"Targets": [
166+
{
167+
"ObjectType": "vnic.EthIf",
168+
"Moid": "{{ vnic_resp.api_response.Moid }}"
169+
}
170+
],
171+
"MergeAction":"Replace"
172+
}
173+
when: vnic_resp.api_response and vnic_resp.changed

0 commit comments

Comments
 (0)