Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions spec/acceptance/st0346a_bash_herd_resolver_spec.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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" }'