-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.yaml
150 lines (138 loc) · 5.17 KB
/
main.yaml
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
---
- hosts: "{{ hosts_pattern }}"
connection: local
name: Dell iDRAC Hosts
gather_facts: False
any_errors_fatal: True
vars:
# Ansible variables assignment if not using Infrared
idrac_query: False
bios_attributes: False
boot_mode: False
boot_order: False
power_action: False
delete_previous_idrac_jobs: False
skip_clear_pending: false
racreset: False
validate_ssl_certs: False
check_bios_jobs: False # This is internal variable not meant to be overridden by users or infrared
pre_tasks:
- name: Build A List Of Variables For iDRAC
set_fact:
host_play_variables: "{{ hostvars[inventory_hostname] }}"
# This allows us to override variables for individual hosts
- name: Append Extra Vars To host_play_variables If Supplied
set_fact:
host_play_variables: "{{ host_play_variables | combine(hostvars[inventory_hostname][inventory_hostname]) }}"
when: "inventory_hostname in hostvars[inventory_hostname]"
- name: Check if can authenticate with iDRAC Using REST API
include_role:
name: idrac_configuration
tasks_from: healthcheck
when: not ansible_check_mode
- name: Reset iDRAC If Requested By User
include_role:
name: idrac_configuration
tasks_from: racreset
when: racreset
tasks:
- name: Query iDRAC
include_role:
name: idrac_configuration
tasks_from: query
when: "'idrac_query' in host_play_variables"
- name: Delete Previous Completed iDRAC Jobs
include_role:
name: idrac_configuration
tasks_from: clear_job_inventory
when: delete_previous_idrac_jobs
- name: Configure Bios
vars:
host_bios_attributes: >-
{%- if 'bios_attributes' in host_play_variables -%}
{{ host_play_variables['bios_attributes'] }}
{%- else -%}
{{ bios_attributes }}
{%- endif -%}
host_boot_mode: >-
{%- if 'boot_mode' in host_play_variables -%}
{{ host_play_variables['boot_mode'] }}
{%- else -%}
{{ boot_mode }}
{%- endif -%}
host_boot_order: >-
{%- if 'boot_order' in host_play_variables -%}
{%- if (host_play_variables['boot_order'] | type_debug) == 'str' -%}
{{ host_play_variables['boot_order'].split(',') }}
{%- elif (host_play_variables['boot_order'] | type_debug) == 'list' -%}
{{ host_play_variables['boot_order'] }}
{%- endif -%}
{%- else -%}
{{ boot_order }}
{%- endif -%}
host_bios_configuration: >-
{%- set bios_dict=dict() -%}
{%- if host_bios_attributes -%}
{{ bios_dict.update(host_bios_attributes) }}
{%- endif -%}
{%- if host_boot_mode -%}
{{ bios_dict.update({'BootMode': host_boot_mode}) }}
{%- endif -%}
{{ bios_dict }}
block:
- name: Delete Pending BIOS Jobs
include_role:
name: idrac_configuration
tasks_from: check_bios
when: not ansible_check_mode
- name: Clear Pending Configuration
include_role:
name: idrac_configuration
tasks_from: clear_pending_configuration
when:
- not ansible_check_mode
- not skip_clear_pending
# In this scenario we will wait for job completion
- name: Update BIOS Configuration - Boot Mode
vars:
bios_config_command: 'SetBiosAttributes'
check_bios_jobs: True
host_bios_configuration:
BootMode: "{{ host_boot_mode }}"
include_role:
name: idrac_configuration
tasks_from: configure_bios
when:
- host_boot_mode is defined
- host_boot_mode in ['Bios', 'Uefi']
- name: Update BIOS Configuration - Boot Attributes
vars:
bios_config_command: 'SetBiosAttributes'
check_bios_jobs: True
include_role:
name: idrac_configuration
tasks_from: configure_bios
when:
- host_bios_attributes
- host_bios_attributes | type_debug == 'dict'
- name: Update BIOS Configuration - Boot Order
vars:
bios_config_command: 'SetBootOrder'
include_role:
name: idrac_configuration
tasks_from: configure_bios
when:
- host_boot_order
- host_boot_order | type_debug == 'list'
# We parse each BIOS attribute individually in order to build a correct config
when: >-
(host_bios_attributes) and (host_bios_attributes | type_debug == 'dict') or
(host_boot_mode) and (host_boot_mode in ['Bios', 'Uefi']) or
(host_boot_order) and (host_boot_order | type_debug == 'list')
- name: Power Action
include_role:
name: idrac_configuration
tasks_from: power_action
when:
- "'power_action' in host_play_variables"
- host_play_variables['power_action'] in ['PowerOn', 'PowerForceOff', 'PowerForceRestart','PowerGracefulRestart', 'PowerGracefulShutdown', 'PowerReboot']