-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathbuild_workflow.pp
More file actions
205 lines (199 loc) · 6.23 KB
/
build_workflow.pp
File metadata and controls
205 lines (199 loc) · 6.23 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# Function: build_workflow
# Builds a workflow for patching based on provided parameters.
#
# @param update_provider_group The update provider for the group.
# @param monitoring_plan_group The monitoring plan for the group.
# @param snapshot_plan_group The snapshot plan for the group.
# @param pre_update_plan_group The pre-update plan for the group.
# @param post_update_plan_group The post-update plan for the group.
# @param reboot_strategy_group The reboot strategy for the group.
# @param reboot_message_group The reboot message for the group.
# @param reboot_wait_group The wait time before reboot for the group.
# @param disconnect_wait_group The wait time before checking disconnect for the group.
# @param noop Flag to enable noop mode for the underlying plans and tasks.
#
# @return Returns a structured data representing the workflow to be executed.
# [
# Update patching cache (yum update, apt-get update, etc)
# { 'name' => 'patching::cache_update', 'type' => 'task', 'params' => { '_noop' => $noop, '_catch_errors' => true } },
# Check for available updates
# { 'name' => 'patching::available_updates', 'type' => 'plan', 'params' => {
# 'provider' => $update_provider_group,
# 'format' => 'pretty',
# 'noop' => $noop
# } },
# Disable monitoring
# { 'name' => $monitoring_plan_group, 'type' => 'plan', 'params' => {
# 'action' => 'disable',
# 'noop' => $noop
# } },
# Create VM snapshots
# { 'name' => $snapshot_plan_group, 'type' => 'plan', 'params' => {
# 'action' => 'create',
# 'noop' => $noop
# } },
# Run pre-patching script
# { 'name' => $pre_update_plan_group, 'type' => 'plan', 'params' => { 'noop' => $noop } },
# Run package updates
# { 'name' => 'patching::update', 'type' => 'task', 'params' => {
# 'provider' => $update_provider_group,
# '_catch_errors' => true,
# 'noop' => $noop
# } },
# Run post-patching script
# { 'name' => $post_update_plan_group, 'type' => 'plan', 'params' => { 'noop' => $noop } },
# Check if reboot required
# { 'name' => 'patching::reboot_required', 'type' => 'plan', 'params' => {
# 'strategy' => $reboot_strategy_group,
# 'message' => $reboot_message_group,
# 'wait' => $reboot_wait_group,
# 'disconnect_wait' => $disconnect_wait_group,
# 'noop' => $noop
# } },
# Remove VM snapshots
# { 'name' => $snapshot_plan_group, 'type' => 'plan', 'params' => {
# 'action' => 'delete',
# 'noop' => $noop
# } },
# Enable monitoring
# { 'name' => $monitoring_plan_group, 'type' => 'plan', 'params' => {
# 'action' => 'enable',
# 'noop' => $noop
# } },
# ]
function patching::build_workflow(
Optional[String] $update_provider_group,
Optional[Boolean] $monitoring_enabled_group,
Optional[String] $monitoring_plan_group,
Optional[Boolean] $snapshot_create_group,
Optional[Boolean] $snapshot_delete_group,
Optional[String] $snapshot_plan_group,
Optional[String] $pre_update_plan_group,
Optional[String] $post_update_plan_group,
Optional[Enum['only_required', 'never', 'always']] $reboot_strategy_group,
Optional[String] $reboot_message_group,
Optional[Integer] $reboot_wait_group,
Optional[Integer] $disconnect_wait_group,
Boolean $noop
) >> Array[Hash] {
# Initialize an array with tasks/plans that are always included
$initial = [
{
'name' => 'patching::cache_update',
'type' => 'task',
'params' => {
'_noop' => $noop,
'_catch_errors' => true,
}
},
{
'name' => 'patching::available_updates',
'type' => 'plan',
'params' => {
'provider' => $update_provider_group,
'format' => 'pretty',
'noop' => $noop,
}
},
]
# Determine if monitoring should be disabled
if $monitoring_enabled_group and $monitoring_plan_group and $monitoring_plan_group != 'disabled' {
$monitoring_plan = [
{
'name' => $monitoring_plan_group,
'type' => 'plan',
'params' => {
'action' => 'disable',
'noop' => $noop,
}
},
]
$monitoring_reenable_group = true
} else {
$monitoring_plan = []
$monitoring_reenable_group = false
}
# Determine if snapshots should be created
if $snapshot_create_group and $snapshot_plan_group and $snapshot_plan_group != 'disabled' {
$snapshot_plan = [
{
'name' => $snapshot_plan_group,
'type' => 'plan',
'params' => {
'action' => 'create',
'noop' => $noop,
}
},
]
} else {
$snapshot_plan = []
}
# Continue adding the rest of the tasks/plans in order
$update = [
{
'name' => $pre_update_plan_group,
'type' => 'plan',
'params' => {
'noop' => $noop,
}
},
{
'name' => 'patching::update',
'type' => 'task',
'params' => {
'provider' => $update_provider_group,
'_catch_errors' => true,
'_noop' => $noop,
}
},
{
'name' => $post_update_plan_group,
'type' => 'plan',
'params' => {
'noop' => $noop,
}
},
{
'name' => 'patching::reboot_required',
'type' => 'plan',
'params' => {
'strategy' => $reboot_strategy_group,
'message' => $reboot_message_group,
'wait' => $reboot_wait_group,
'disconnect_wait' => $disconnect_wait_group,
'noop' => $noop,
}
},
]
# Conditionally append the remove VM snapshots and enable monitoring plans at the end
if $snapshot_delete_group and $snapshot_plan_group and $snapshot_plan_group != 'disabled' {
$snapshot_delete = [
{
'name' => $snapshot_plan_group,
'type' => 'plan',
'params' => {
'action' => 'delete',
'noop' => $noop,
}
},
]
} else {
$snapshot_delete = []
}
if $monitoring_reenable_group and $monitoring_plan_group and $monitoring_plan_group != 'disabled' {
$monitoring_reenable = [
{
'name' => $monitoring_plan_group,
'type' => 'plan',
'params' => {
'action' => 'enable',
'noop' => $noop,
}
},
]
} else {
$monitoring_reenable = []
}
# Return the complete workflow array
return $initial + $monitoring_plan + $snapshot_plan + $update + $snapshot_delete + $monitoring_reenable
}