foreman_job_template – Manage Job Templates in Foreman

Synopsis

  • Manage Foreman Remote Execution Job Templates

Requirements

The below requirements are needed on the host that executes this module.

  • apypie

Parameters

Parameter Choices/Defaults Comments
audit_comment
string
Content of the audit comment field
description_format
string
description of the job template. Template inputs can be referenced.
file_name
path
The path of a template file, that shall be imported. Either this or layout is required as a source for the Job Template "content".
job_category
string
The category the template should be assigend to
locations
list / elements=string
List of locations the entity should be assigned to
locked
boolean
    Choices:
  • no ←
  • yes
Determines whether the template shall be locked
name
string
The name a template should be assigned with in Foreman. name must be provided. Possible sources are, ordererd by preference: The "name" parameter, config header (inline or in a file), basename of a file. The special name "*" (only possible as parameter) is used to perform bulk actions (modify, delete) on all existing Job Templates.
organizations
list / elements=string
List of organizations the entity should be assigned to
password
string / required
Password of the user accessing the Foreman server
provider_type
string
Determines via which provider the template shall be executed
server_url
string / required
URL of the Foreman server
snippet
boolean
    Choices:
  • no ←
  • yes
Determines whether the template shall be a snippet
state
string
    Choices:
  • present ←
  • present_with_defaults
  • absent
State of the entity in Foreman
present_with_defaults will ensure the entity exists, but won't update existing ones
template
string
The content of the Job Template, either this or file_name is required as a source for the Job Template "content".
template_inputs
list / elements=dictionary
The template inputs used in the Job Template
advanced
boolean
    Choices:
  • no ←
  • yes
Template Input is advanced
description
string
description of the Template Input
fact_name
string
Fact name, used when input type is fact
input_type
string / required
    Choices:
  • user
  • fact
  • variable
  • puppet_parameter
input type
name
string / required
name of the Template Input
options
list / elements=raw
Template values for user inputs. Must be an array of any type.
puppet_class_name
string
Puppet class name, used when input type is puppet_parameter
puppet_parameter_name
string
Puppet parameter name, used when input type is puppet_parameter
required
boolean
    Choices:
  • no
  • yes
Is the input required
resource_type
string
Type of the resource
value_type
string
    Choices:
  • plain
  • search
  • date
Type of the value
variable_name
string
Variable name, used when input type is variable
username
string / required
Username accessing the Foreman server
validate_certs
boolean
    Choices:
  • no
  • yes ←
Whether or not to verify the TLS certificates of the Foreman server

aliases: verify_ssl

Examples

- name: "Create a Job Template inline"
  foreman_job_template:
    username: "admin"
    password: "changeme"
    server_url: "https://foreman.example.com"
    name: A New Job Template
    state: present
    template: |
      <%#
          name: A Job Template
      %>
      rm -rf <%= input("toDelete") %>
    template_inputs:
      - name: toDelete
        input_type: user
    locations:
    - Gallifrey
    organizations:
    - TARDIS INC

- name: "Create a Job Template from a file"
  foreman_job_template:
    username: "admin"
    password: "changeme"
    server_url: "https://foreman.example.com"
    name: a new job template
    file_name: timeywimey_template.erb
    template_inputs:
      - name: a new template input
        input_type: user
    state: present
    locations:
    - Gallifrey
    organizations:
    - TARDIS INC

- name: "remove a job template's template inputs"
  foreman_job_template:
    username: "admin"
    password: "changeme"
    server_url: "https://foreman.example.com"
    name: a new job template
    template_inputs: []
    state: present
    locations:
    - Gallifrey
    organizations:
    - TARDIS INC

- name: "Delete a Job Template"
  foreman_job_template:
    username: "admin"
    password: "changeme"
    server_url: "https://foreman.example.com"
    name: timeywimey
    state: absent

- name: "Create a Job Template from a file and modify with parameter(s)"
  foreman_job_template:
    username: "admin"
    password: "changeme"
    server_url: "https://foreman.example.com"
    file_name: timeywimey_template.erb
    name: Wibbly Wobbly Template
    state: present
    locations:
    - Gallifrey
    organizations:
    - TARDIS INC

# Providing a name in this case wouldn't be very sensible.
# Alternatively make use of with_filetree to parse recursively with filter.
- name: Parsing a directory of Job templates
  foreman_job_template:
    username: "admin"
    password: "changeme"
    server_url: "https://foreman.example.com"
    file_name: "{{ item }}"
    state: present
    locations:
    - SKARO
    organizations:
    - DALEK INC
    with_fileglob:
     - "./arsenal_templates/*.erb"

# If the templates are stored locally and the ansible module is executed on a remote host
- name: Ensure latest version of all your Job Templates
  foreman_job_template:
    server_url: "https://foreman.example.com"
    username:  "admin"
    password:  "changeme"
    state: present
    layout: '{{ lookup("file", item.src) }}'
  with_filetree: '/path/to/job/templates'
  when: item.state == 'file'


# with name set to "*" bulk actions can be performed
- name: "Delete *ALL* Job Templates"
  local_action:
    module: foreman_job_template
    username: "admin"
    password: "admin"
    server_url: "https://foreman.example.com"
    name: "*"
    state: absent

- name: "Assign all Job Templates to the same organization(s)"
  local_action:
    module: foreman_job_template
    username: "admin"
    password: "admin"
    server_url: "https://foreman.example.com"
    name: "*"
    state: present
    organizations:
    - DALEK INC
    - sky.net
    - Doc Brown's garage

Status

Authors

  • Manuel Bonk (@manuelbonk) ATIX AG

  • Matthias Dellweg (@mdellweg) ATIX AG

Hint

If you notice any issues in this documentation, you can edit this document to improve it.