This repository has been archived by the owner on Jul 9, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add remote execution jobs to community-templates
- Loading branch information
Showing
6 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Job Templates | ||
|
||
This directory contains job templates for the | ||
[foreman_remote_execution](https://github.com/theforeman/foreman_remote_execution/) | ||
plugin. | ||
|
||
## Contributing | ||
|
||
If you think a job is useful to include here, feel free to open an PR. | ||
foreman_remote_execution 0.3.2 supports directly exporting your job template | ||
into an appropriate format, with metadata in the first ERB comment. | ||
|
||
Thanks! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<%# | ||
kind: job_template | ||
name: Package Action - SSH Default | ||
job_category: Packages | ||
description_format: "%{action} package(s) %{package}" | ||
provider_type: SSH | ||
template_inputs: | ||
- name: pre_script | ||
description: A script to run prior to the package action | ||
input_type: user | ||
required: false | ||
advanced: true | ||
- name: action | ||
description: 'The package action: install, update, or remove' | ||
input_type: user | ||
required: true | ||
options: "install\nupdate\nremove\ngroup install\ngroup remove" | ||
- name: package | ||
description: The name of the package, if any | ||
input_type: user | ||
required: false | ||
- name: post_script | ||
description: A script to run after the package action | ||
input_type: user | ||
required: false | ||
advanced: true | ||
%> | ||
<% | ||
supported_families = ['Redhat', 'Debian'] | ||
render_error(N_('Unsupported or no operating system found for this host.')) unless @host.operatingsystem && supported_families.include?(@host.operatingsystem.family) | ||
%> | ||
|
||
# Helper function that exits with a particular message and code. | ||
# | ||
# Usage: | ||
# exit_with_message "Could not do a thing" 2 | ||
# | ||
function exit_with_message() { | ||
echo "${1}, exiting..." | ||
exit $2 | ||
} | ||
|
||
<% unless input("pre_script").blank? -%> | ||
# Pre Script | ||
<%= input("pre_script") %> | ||
RETVAL=$? | ||
[ $RETVAL -eq 0 ] || exit_with_message "Pre script failed" $RETVAL | ||
<% end -%> | ||
|
||
# Action | ||
<% if @host.operatingsystem.family == 'Redhat' -%> | ||
yum -y <%= input("action") %> <%= input("package") %> | ||
<% elsif @host.operatingsystem.family == 'Debian' -%> | ||
apt-get -y <%= input("action") %> <%= input("package") %> | ||
<% end -%> | ||
RETVAL=$? | ||
[ $RETVAL -eq 0 ] || exit_with_message "Package action failed" $RETVAL | ||
|
||
<% unless input("post_script").blank? -%> | ||
# Post Script | ||
<%= input("post_script") %> | ||
RETVAL=$? | ||
[ $RETVAL -eq 0 ] || exit_with_message "Post script failed" $RETVAL | ||
<% end -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<%# | ||
kind: job_template | ||
name: Power Action - SSH Default | ||
job_category: Power | ||
description_format: '%{action} host' | ||
provider_type: SSH | ||
template_inputs: | ||
- name: action | ||
description: Action to perform on the service | ||
input_type: user | ||
options: "restart\nshutdown" | ||
required: true | ||
%> | ||
|
||
echo <%= input('action') %> host && sleep 3 | ||
<%= case input('action') | ||
when 'restart' | ||
'reboot' | ||
else | ||
'shutdown -h now' | ||
end %> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<%# | ||
kind: job_template | ||
name: Puppet Run Once - SSH Default | ||
job_category: Puppet | ||
description_format: 'Run Puppet once with "%{puppet_options}"' | ||
provider_type: SSH | ||
template_inputs: | ||
- name: puppet_options | ||
description: Additional options to pass to puppet | ||
input_type: user | ||
required: false | ||
%> | ||
puppet agent --onetime --no-usecacheonfailure <%= input("puppet_options") %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<%# | ||
kind: job_template | ||
name: Run Command - SSH Default | ||
job_category: Commands | ||
description_format: "Run %{command}" | ||
provider_type: SSH | ||
template_inputs: | ||
- name: command | ||
description: Command to run on the host | ||
input_type: user | ||
required: true | ||
%> | ||
<%= input("command") %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<%# | ||
kind: job_template | ||
name: Service Action - SSH Default | ||
job_category: Services | ||
description_format: '%{action} service %{service}' | ||
provider_type: SSH | ||
template_inputs: | ||
- name: action | ||
description: Action to perform on the service | ||
input_type: user | ||
options: "restart\nstart\nstop\nstatus" | ||
required: true | ||
- name: service | ||
description: Name of the service | ||
input_type: user | ||
required: true | ||
%> | ||
<% if @host.operatingsystem.family == "Redhat" && @host.operatingsystem.major.to_i > 6 %> | ||
systemctl <%= input("action") %> <%= input("service") %> | ||
<% else %> | ||
service <%= input("service") %> <%= input("action") %> | ||
<% end -%> |