theforeman.foreman.job_template (4.0.0) — module

Manage Job Templates

| "added in version" 1.0.0 of theforeman.foreman"

Authors: Manuel Bonk (@manuelbonk) ATIX AG, Matthias Dellweg (@mdellweg) ATIX AG

Install collection

Install with ansible-galaxy collection install theforeman.foreman:==4.0.0


Add to requirements.yml

  collections:
    - name: theforeman.foreman
      version: 4.0.0

Description

Manage Remote Execution Job Templates


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.

- name: "Create a Job Template inline"
  theforeman.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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Create a Job Template from a file"
  theforeman.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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "remove a job template's template inputs"
  theforeman.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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Delete a Job Template"
  theforeman.foreman.job_template:
    username: "admin"
    password: "changeme"
    server_url: "https://foreman.example.com"
    name: timeywimey
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Create a Job Template from a file and modify with parameter(s)"
  theforeman.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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  theforeman.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"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  theforeman.foreman.job_template:
    server_url: "https://foreman.example.com"
    username: "admin"
    password: "changeme"
    state: present
    template: '{{ lookup("file", item.src) }}'
    name: '{{ item.path }}'
  with_filetree: '/path/to/job/templates'
  when: item.state == 'file'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.

# with name set to "*" bulk actions can be performed
- name: "Delete *ALL* Job Templates"
  theforeman.foreman.job_template:
    username: "admin"
    password: "changeme"
    server_url: "https://foreman.example.com"
    name: "*"
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Assign all Job Templates to the same organization(s)"
  theforeman.foreman.job_template:
    username: "admin"
    password: "changeme"
    server_url: "https://foreman.example.com"
    name: "*"
    state: present
    organizations:
      - DALEK INC
      - sky.net
      - Doc Brown's garage

Inputs

    
name:
    description:
    - The name of the Job Template.
    - If omited, will be determined from the C(name) header of the template or the filename
      (in that order).
    - The special value "*" can be used to perform bulk actions (modify, delete) on all
      existing templates.
    type: str

state:
    choices:
    - present
    - present_with_defaults
    - absent
    default: present
    description:
    - State of the entity
    - C(present_with_defaults) will ensure the entity exists, but won't update existing
      ones
    type: str

locked:
    default: false
    description:
    - Determines whether the template shall be locked
    type: bool

snippet:
    description:
    - Determines whether the template shall be a snippet
    type: bool

password:
    description:
    - Password of the user accessing the Foreman server.
    - If the value is not specified in the task, the value of environment variable C(FOREMAN_PASSWORD)
      will be used instead.
    required: true
    type: str

template:
    description:
    - The content of the Job Template.
    - Either this or I(file_name) is required as a source for the Job Template "content".
    type: str

username:
    description:
    - Username accessing the Foreman server.
    - If the value is not specified in the task, the value of environment variable C(FOREMAN_USERNAME)
      will be used instead.
    required: true
    type: str

file_name:
    description:
    - The path of a template file, that shall be imported.
    - Either this or I(template) is required as a source for the Job Template "content".
    type: path

locations:
    description: List of locations the entity should be assigned to
    elements: str
    type: list

server_url:
    description:
    - URL of the Foreman server.
    - If the value is not specified in the task, the value of environment variable C(FOREMAN_SERVER_URL)
      will be used instead.
    required: true
    type: str

job_category:
    description:
    - The category the template should be assigend to
    type: str

audit_comment:
    description:
    - Content of the audit comment field
    type: str

organizations:
    description: List of organizations the entity should be assigned to
    elements: str
    type: list

provider_type:
    description:
    - Determines via which provider the template shall be executed
    required: false
    type: str

validate_certs:
    default: true
    description:
    - Whether or not to verify the TLS certificates of the Foreman server.
    - If the value is not specified in the task, the value of environment variable C(FOREMAN_VALIDATE_CERTS)
      will be used instead.
    type: bool

template_inputs:
    description:
    - The template inputs used in the Job Template
    elements: dict
    suboptions:
      advanced:
        description:
        - Template Input is advanced
        type: bool
      default:
        description:
        - Default value for user input
        type: str
        version_added: 3.8.0
        version_added_collection: theforeman.foreman
      description:
        description:
        - description of the Template Input
        type: str
      fact_name:
        description:
        - Fact name to use.
        - Required when I(input_type=fact).
        type: str
      hidden_value:
        description:
        - The value contains sensitive information and should't be normally visible, useful
          e.g. for passwords
        type: bool
      input_type:
        choices:
        - user
        - fact
        - variable
        - puppet_parameter
        description:
        - input type
        required: true
        type: str
      name:
        description:
        - name of the Template Input
        required: true
        type: str
      options:
        description:
        - Template values for user inputs. Must be an array of any type.
        elements: raw
        type: list
      puppet_class_name:
        description:
        - Puppet class name.
        - Required when I(input_type=puppet_parameter).
        type: str
      puppet_parameter_name:
        description:
        - Puppet parameter name.
        - Required when I(input_type=puppet_parameter).
        type: str
      required:
        description:
        - Is the input required
        type: bool
      resource_type:
        description:
        - Type of the resource
        type: str
      value_type:
        choices:
        - plain
        - search
        - date
        - resource
        description:
        - Type of the value
        type: str
      variable_name:
        description:
        - Variable name to use.
        - Required when I(input_type=variable).
        type: str
    type: list

description_format:
    description:
    - description of the job template. Template inputs can be referenced.
    type: str

Outputs

entity:
  contains:
    job_templates:
      description: List of job templates.
      elements: dict
      type: list
    template_inputs:
      description: List of template inputs associated with the job template.
      elements: dict
      type: list
  description: Final state of the affected entities grouped by their type.
  returned: success
  type: dict