summaryrefslogtreecommitdiffstats
path: root/ansible_collections/cisco/intersight/playbooks/derive_profiles.yml
blob: 9f8ef51f8a1fa60014a7f422b6ab4129ace7f0fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
#
# include_tasks for deriving profiles from a template
#
# Get the Organization Moid
- name: "Get {{ template_name }}_DERIVED-{{ item }} Profile Moid"
  intersight_rest_api:
    api_private_key: "{{ api_private_key | default(omit) }}"
    api_key_id: "{{ api_key_id | default(omit) }}"
    api_uri: "{{ api_uri | default(omit) }}"
    validate_certs: "{{ validate_certs | default(omit) }}"
    state: "{{ state | default(omit) }}"
    resource_path: /server/Profiles
    query_params:
      $filter: "Name eq '{{ template_name }}_DERIVED-{{ item }}'"
  register: profile_resp
# Derive profiles from template (if profiles don't already exist)
- name: "POST to derive {{ template_name }}_DERIVED-{{ item }}"
  intersight_rest_api:
    api_private_key: "{{ api_private_key | default(omit) }}"
    api_key_id: "{{ api_key_id | default(omit) }}"
    api_uri: "{{ api_uri | default(omit) }}"
    validate_certs: "{{ validate_certs | default(omit) }}"
    state: "{{ state | default(omit) }}"
    resource_path: /bulk/MoCloners
    update_method: post
    api_body: {
      "Sources": [
        {
          "ClassId": "mo.MoRef",
          "ObjectType": "server.ProfileTemplate",
          "Moid": "{{ template_resp.api_response.Moid }}"
        }
      ],
      "Targets": [
        {
          "Name": "{{ template_name }}_DERIVED-{{ item }}",
          "ObjectType": "server.Profile",
          "Organization": {
            "Moid": "{{ org_resp.api_response.Moid }}"
          },
          "ClassId": "server.Profile"
        }
      ]
    }
  when: profile_resp.api_response is not defined or not profile_resp.api_response
# POST updates to derived profiles if template was changed
- name: "POST to update {{ template_name }}_DERIVED-{{ item }}"
  intersight_rest_api:
    api_private_key: "{{ api_private_key | default(omit) }}"
    api_key_id: "{{ api_key_id | default(omit) }}"
    api_uri: "{{ api_uri | default(omit) }}"
    validate_certs: "{{ validate_certs | default(omit) }}"
    state: "{{ state | default(omit) }}"
    resource_path: /bulk/MoMergers
    update_method: post
    api_body: {
      "Sources": [
        {
          "ObjectType": "server.ProfileTemplate",
          "Moid": "{{ template_resp.api_response.Moid }}"
        }
      ],
      "Targets": [
        {
          "ObjectType": "server.Profile",
          "Moid": "{{ profile_resp.api_response.Moid }}"
        }
      ],
      "MergeAction":"Replace"
    }
  when: profile_resp.api_response and template_resp.changed