Skip to content
This repository has been archived by the owner on Jul 9, 2020. It is now read-only.

Commit

Permalink
Add remote execution jobs to community-templates
Browse files Browse the repository at this point in the history
  • Loading branch information
stbenjam committed Apr 28, 2016
1 parent 835acaa commit 6d28112
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 0 deletions.
13 changes: 13 additions & 0 deletions jobs/README.md
@@ -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 and newer support directly exporting your job
template into an appropriate format, with metadata in the first ERB comment.

Thanks!
65 changes: 65 additions & 0 deletions jobs/ssh/package_action.erb
@@ -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 -%>
22 changes: 22 additions & 0 deletions jobs/ssh/power_action.erb
@@ -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 %>

13 changes: 13 additions & 0 deletions jobs/ssh/puppet_run_once.erb
@@ -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") %>
13 changes: 13 additions & 0 deletions jobs/ssh/run_command.erb
@@ -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") %>
22 changes: 22 additions & 0 deletions jobs/ssh/service_action.erb
@@ -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 -%>

0 comments on commit 6d28112

Please sign in to comment.