此内容没有您所选择的语言版本。
Appendix A. Job Template Examples and Extensions
Use this section as a reference to help modify, customize, and extend your job templates to suit your requirements.
A.1. Customizing Job Templates
When creating a job template, you can include an existing template in the template editor field. This way you can combine templates, or create more specific templates from the general ones.
The following template combines default templates to install and start the httpd service on Red Hat Enterprise Linux systems:
<%= render_template 'Package Action - SSH Default', :action => 'install', :package => 'httpd' %> <%= render_template 'Service Action - SSH Default', :action => 'start', :service_name => 'httpd' %>
The above template specifies parameter values for the rendered template directly. It is also possible to use the input() method to allow users to define input for the rendered template on job execution. For example, you can use the following syntax:
<%= render_template 'Package Action - SSH Default', :action => 'install', :package => input("package") %>
With the above template, you have to import the parameter definition from the rendered template. To do so, navigate to the Jobs tab, click Add Foreign Input Set, and select the rendered template from the Target template list. You can import all parameters or specify a comma separated list.
A.2. Default Job Template Categories
Job template category | Description |
---|---|
Packages | Templates for performing package related actions. Install, update, and remove actions are included by default. |
Puppet | Templates for executing Puppet runs on target hosts. |
Power | Templates for performing power related actions. Restart and shutdown actions are included by default. |
Commands | Templates for executing custom commands on remote hosts. |
Services | Templates for performing service related actions. Start, stop, restart, and status actions are included by default. |
Katello | Templates for performing content related actions. These templates are used mainly from different parts of the Satellite web UI (for example bulk actions UI for content hosts), but can be used separately to perform operations such as errata installation. |
A.3. Example restorecon Template
This example shows how to create a template called Run Command - restorecon that restores the default SELinux context for all files in the selected directory on target hosts.
- Navigate to Hosts > Job templates. Click New Job Template.
Enter Run Command - restorecon in the Name field. Select Default to make the template available to all organizations. Add the following text to the template editor:
restorecon -RvF <%= input("directory") %>
The
<%= input("directory") %>
string is replaced by a user-defined directory during job invocation.-
On the Job tab, set Job category to
Commands
. -
Click Add Input to allow job customization. Enter
directory
to the Name field. The input name must match the value specified in the template editor. - Click Required so that the command cannot be executed without the user specified parameter.
-
Select User input from the Input type list. Enter a description to be shown during job invocation, for example
Target directory for restorecon
. - Click Submit.
See Section A.5, “Executing a restorecon Template on Multiple Hosts” for information on how to execute a job based on this template.
A.4. Rendering a restorecon Template
This example shows how to create a template derived from the Run command - restorecon template created in Section A.3, “Example restorecon Template”. This template does not require user input on job execution, it will restore the SELinux context in all files under the /home/ directory on target hosts.
Create a new template as described in Section 3.14, “Setting up Job Templates”, and specify the following string in the template editor:
<%= render_template("Run Command - restorecon", :directory => "/home") %>
A.5. Executing a restorecon Template on Multiple Hosts
This example shows how to run a job based on the template created in Section A.3, “Example restorecon Template” on multiple hosts. The job restores the SELinux context in all files under the /home/ directory.
- Navigate to Hosts > All hosts and select target hosts. Select Schedule Remote Job from the Select Action list.
-
In the Job invocation page, select the
Commands
job category and theRun Command - restorecon
job template. -
Type
/home
in the directory field. -
Set Schedule to
Execute now
. - Click Submit. You are taken to the Job invocation page where you can monitor the status of job execution.
A.6. Including Power Actions in Templates
This example shows how to set up a job template for performing power actions, such as reboot. This procedure prevents Satellite from interpreting the disconnect exception upon reboot as an error, and consequently, remote execution of the job works correctly.
Create a new template as described in Section 3.14, “Setting up Job Templates”, and specify the following string in the template editor:
<%= render_template("Power Action - SSH Default", :action => "restart") %>