Skip to content

Commit

Permalink
Merge pull request #129 from MartyEwings/SUP-2847
Browse files Browse the repository at this point in the history
(SUP-2847) Structured Returns for Herd resolver
  • Loading branch information
MartyEwings committed Dec 20, 2021
2 parents 267dc09 + 4a284f1 commit 3cd214c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
3 changes: 1 addition & 2 deletions spec/acceptance/st0346a_bash_herd_resolver_spec.rb
Expand Up @@ -3,7 +3,6 @@
it 'when restarting agent ' do
run_shell('/opt/puppetlabs/bin/puppet config set runinterval 5')
result = run_bolt_task('support_tasks::st0346a_bash_herd_resolver')
expect(result['result']['_output']).to contain('running')
expect(result['result']['_output']).to contain('stopped')
expect(result.stdout).to contain(%r{success})
end
end
2 changes: 1 addition & 1 deletion tasks/st0346_herd_resolver.json
Expand Up @@ -5,7 +5,7 @@
"parameters": {
},
"implementations": [
{"name": "st0346a_bash_herd_resolver.sh", "requirements": ["shell"]},
{"name": "st0346a_bash_herd_resolver.sh", "requirements": ["shell"], "files": ["bash_task_helper/files/task_helper.sh"], "input_method": "environment"},
{"name": "st0346b_powershell_herd_resolver.ps1", "requirements": ["powershell"]}
]
}
Expand Down
5 changes: 4 additions & 1 deletion tasks/st0346a_bash_herd_resolver.json
Expand Up @@ -3,5 +3,8 @@
"supports_noop": false,
"description": "This Task will restart the puppet agent process in a randomised period between 0 and the currently set runinterval",
"parameters": {
}
},
"implementations": [
{"name": "st0346a_bash_herd_resolver.sh", "requirements": ["shell"], "files": ["bash_task_helper/files/task_helper.sh"], "input_method": "environment"}
]
}
10 changes: 7 additions & 3 deletions tasks/st0346a_bash_herd_resolver.sh
@@ -1,9 +1,13 @@
#!/bin/bash
declare PT__installdir
source "$PT__installdir/bash_task_helper/files/task_helper.sh"

# Puppet Task Name: bash_herd_resolver
# This task is to be run on operating systems using a bash shell
# It will randomise the restart of the puppet agent based on the current value of runinterval

sleep $(( ( RANDOM % $(/opt/puppetlabs/bin/puppet agent --configprint runinterval) ) + 1 ))s
/opt/puppetlabs/bin/puppet resource service puppet ensure=stopped
/opt/puppetlabs/bin/puppet resource service puppet ensure=running
sleep $(( ( RANDOM % $(/opt/puppetlabs/bin/puppet agent --configprint runinterval) ) + 1 ))s || fail "unable to set random sleep interval "
/opt/puppetlabs/bin/puppet resource service puppet ensure=stopped || fail "unable stop puppet service "
/opt/puppetlabs/bin/puppet resource service puppet ensure=running || fail "unable start puppet service "

success '{ "status": "success - Agent restarted at random interval" }'

0 comments on commit 3cd214c

Please sign in to comment.