-
Notifications
You must be signed in to change notification settings - Fork 16
/
puppet-selective-enforcement.yaml
63 lines (62 loc) · 2.06 KB
/
puppet-selective-enforcement.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
apiVersion: v1
summary: Selectively enforce Puppet run
description: This workflow selectively enforces a Puppet run when changes are detected
homepage: https://github.com/puppetlabs/relay-workflows/tree/master/puppet-selective-enforcement
tags:
- auto remediation
parameters:
host:
description: "Hostname that submitted the report"
noop:
description: Whether this was a no-op run
default: true
resourceStatuses:
description: The changed resources
triggers:
- name: puppet-report
source:
type: push
binding:
parameters:
host: !Data host
noop: !Data noop
resourceStatuses: !Data resource_statuses
steps:
- name: view-puppet-resources
image: relaysh/core
spec:
resourceStatuses: !Parameter resourceStatuses
input:
- ni get | jq .resourceStatuses
- name: detect-corrective-changes
image: relaysh/core
dependsOn: view-puppet-resources
spec:
resourceStatuses: !Parameter resourceStatuses
input:
- DETECTED_CHANGES=$(ni get | jq -r '.resourceStatuses | to_entries[] | select(.value.corrective_change) | .key')
- 'echo "Detected changes, if any: ${DETECTED_CHANGES}"'
- 'if [ x = x${DETECTED_CHANGES} ] ; then ni output set -k detectedChanges -v none; else ni output set -k detectedChanges -v "${DETECTED_CHANGES}" ; fi'
- name: approval
description: Wait for approval to run Puppet for real
type: approval
dependsOn: detect-corrective-changes
when:
- !Parameter noop
- !Fn.notEquals [ !Output { from: detect-corrective-changes, name: detectedChanges }, none ]
- name: start-puppet-run
image: relaysh/puppet-step-run-start
dependsOn: approval
spec:
connection: !Connection { type: puppet, name: my-puppet-connection}
environment: production
scope:
nodes:
- !Parameter host
- name: wait-for-puppet-run
image: relaysh/puppet-step-run-wait
dependsOn: start-puppet-run
spec:
connection: !Connection { type: puppet, name: my-puppet-connection}
id:
!Output [ start-puppet-run, id ]