community.general.jenkins_plugin (8.5.0) — module

Add or remove Jenkins plugin

Authors: Jiri Tyr (@jtyr)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Ansible module which helps to manage Jenkins plugins.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Install plugin
  community.general.jenkins_plugin:
    name: build-pipeline-plugin
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Install plugin without its dependencies
  community.general.jenkins_plugin:
    name: build-pipeline-plugin
    with_dependencies: false
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Make sure the plugin is always up-to-date
  community.general.jenkins_plugin:
    name: token-macro
    state: latest
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Install specific version of the plugin
  community.general.jenkins_plugin:
    name: token-macro
    version: "1.15"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Pin the plugin
  community.general.jenkins_plugin:
    name: token-macro
    state: pinned
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Unpin the plugin
  community.general.jenkins_plugin:
    name: token-macro
    state: unpinned
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Enable the plugin
  community.general.jenkins_plugin:
    name: token-macro
    state: enabled
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Disable the plugin
  community.general.jenkins_plugin:
    name: token-macro
    state: disabled
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Uninstall plugin
  community.general.jenkins_plugin:
    name: build-pipeline-plugin
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
#
# Example of how to authenticate
#
- name: Install plugin
  community.general.jenkins_plugin:
    name: build-pipeline-plugin
    url_username: admin
    url_password: p4ssw0rd
    url: http://localhost:8888
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
#
# Example of how to authenticate with serverless deployment
#
- name: Update plugins on ECS Fargate Jenkins instance
  community.general.jenkins_plugin:
    # plugin name and version
    name: ws-cleanup
    version: '0.45'
    # Jenkins home path mounted on ec2-helper VM (example)
    jenkins_home: "/mnt/{{ jenkins_instance }}"
    # matching the UID/GID to one in official Jenkins image
    owner: 1000
    group: 1000
    # Jenkins instance URL and admin credentials
    url: "https://{{ jenkins_instance }}.com/"
    url_username: admin
    url_password: p4ssw0rd
  # make module work from EC2 which has local access
  # to EFS mount as well as Jenkins URL
  delegate_to: ec2-helper
  vars:
    jenkins_instance: foobar
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
#
# Example of a Play which handles Jenkins restarts during the state changes
#
- name: Jenkins Master play
  hosts: jenkins-master
  vars:
    my_jenkins_plugins:
      token-macro:
        enabled: true
      build-pipeline-plugin:
        version: "1.4.9"
        pinned: false
        enabled: true
  tasks:
    - name: Install plugins without a specific version
      community.general.jenkins_plugin:
        name: "{{ item.key }}"
      register: my_jenkins_plugin_unversioned
      when: >
        'version' not in item.value
      with_dict: "{{ my_jenkins_plugins }}"

    - name: Install plugins with a specific version
      community.general.jenkins_plugin:
        name: "{{ item.key }}"
        version: "{{ item.value['version'] }}"
      register: my_jenkins_plugin_versioned
      when: >
        'version' in item.value
      with_dict: "{{ my_jenkins_plugins }}"

    - name: Initiate the fact
      ansible.builtin.set_fact:
        jenkins_restart_required: false

    - name: Check if restart is required by any of the versioned plugins
      ansible.builtin.set_fact:
        jenkins_restart_required: true
      when: item.changed
      with_items: "{{ my_jenkins_plugin_versioned.results }}"

    - name: Check if restart is required by any of the unversioned plugins
      ansible.builtin.set_fact:
        jenkins_restart_required: true
      when: item.changed
      with_items: "{{ my_jenkins_plugin_unversioned.results }}"

    - name: Restart Jenkins if required
      ansible.builtin.service:
        name: jenkins
        state: restarted
      when: jenkins_restart_required

    - name: Wait for Jenkins to start up
      ansible.builtin.uri:
        url: http://localhost:8080
        status_code: 200
        timeout: 5
      register: jenkins_service_status
      # Keep trying for 5 mins in 5 sec intervals
      retries: 60
      delay: 5
      until: >
         'status' in jenkins_service_status and
         jenkins_service_status['status'] == 200
      when: jenkins_restart_required

    - name: Reset the fact
      ansible.builtin.set_fact:
        jenkins_restart_required: false
      when: jenkins_restart_required

    - name: Plugin pinning
      community.general.jenkins_plugin:
        name: "{{ item.key }}"
        state: "{{ 'pinned' if item.value['pinned'] else 'unpinned'}}"
      when: >
        'pinned' in item.value
      with_dict: "{{ my_jenkins_plugins }}"

    - name: Plugin enabling
      community.general.jenkins_plugin:
        name: "{{ item.key }}"
        state: "{{ 'enabled' if item.value['enabled'] else 'disabled'}}"
      when: >
        'enabled' in item.value
      with_dict: "{{ my_jenkins_plugins }}"

Inputs

    
url:
    default: http://localhost:8080
    description:
    - URL of the Jenkins server.
    type: str

mode:
    default: '0644'
    description:
    - File mode applied on versioned plugins.
    type: raw

name:
    description:
    - Plugin name.
    required: true
    type: str

force:
    default: false
    description:
    - If V(yes) do not get a cached copy.
    type: bool

group:
    default: jenkins
    description:
    - GID or name of the Jenkins group on the OS.
    type: str

owner:
    default: jenkins
    description:
    - UID or name of the Jenkins user on the OS.
    type: str

state:
    choices:
    - absent
    - present
    - pinned
    - unpinned
    - enabled
    - disabled
    - latest
    default: present
    description:
    - Desired plugin state.
    - If set to V(latest), the check for new version will be performed every time. This
      is suitable to keep the plugin up-to-date.
    type: str

serole:
    description:
    - The role part of the SELinux filesystem object context.
    - When set to V(_default), it will use the C(role) portion of the policy if available.
    type: str

setype:
    description:
    - The type part of the SELinux filesystem object context.
    - When set to V(_default), it will use the C(type) portion of the policy if available.
    type: str

seuser:
    description:
    - The user part of the SELinux filesystem object context.
    - By default it uses the V(system) policy, where applicable.
    - When set to V(_default), it will use the C(user) portion of the policy if available.
    type: str

selevel:
    description:
    - The level part of the SELinux filesystem object context.
    - This is the MLS/MCS attribute, sometimes known as the C(range).
    - When set to V(_default), it will use the C(level) portion of the policy if available.
    type: str

timeout:
    default: 30
    description:
    - Server connection timeout in secs.
    type: int

version:
    description:
    - Plugin version number.
    - If this option is specified, all plugin dependencies must be installed manually.
    - It might take longer to verify that the correct version is installed. This is especially
      true if a specific version number is specified.
    - Quote the version to prevent the value to be interpreted as float. For example if
      V(1.20) would be unquoted, it would become V(1.2).
    type: str

use_proxy:
    default: true
    description:
    - If V(no), it will not use a proxy, even if one is defined in an environment variable
      on the target hosts.
    type: bool

attributes:
    aliases:
    - attr
    description:
    - The attributes the resulting filesystem object should have.
    - To get supported flags look at the man page for I(chattr) on the target system.
    - This string should contain the attributes in the same order as the one displayed
      by I(lsattr).
    - The C(=) operator is assumed as default, otherwise C(+) or C(-) operators need to
      be included in the string.
    type: str
    version_added: '2.3'
    version_added_collection: ansible.builtin

client_key:
    description:
    - PEM formatted file that contains your private key to be used for SSL client authentication.
    - If O(client_cert) contains both the certificate and key, this option is not required.
    type: path

http_agent:
    default: ansible-httpget
    description:
    - Header to identify as, generally appears in web server logs.
    type: str

use_gssapi:
    default: false
    description:
    - Use GSSAPI to perform the authentication, typically this is for Kerberos or Kerberos
      through Negotiate authentication.
    - Requires the Python library L(gssapi,https://github.com/pythongssapi/python-gssapi)
      to be installed.
    - Credentials for GSSAPI can be specified with O(url_username)/O(url_password) or
      with the GSSAPI env var C(KRB5CCNAME) that specified a custom Kerberos credential
      cache.
    - NTLM authentication is B(not) supported even if the GSSAPI mech for NTLM has been
      installed.
    type: bool
    version_added: '2.11'
    version_added_collection: ansible.builtin

client_cert:
    description:
    - PEM formatted certificate chain file to be used for SSL client authentication.
    - This file can also include the key as well, and if the key is included, O(client_key)
      is not required.
    type: path

updates_url:
    default:
    - https://updates.jenkins.io
    - http://mirrors.jenkins.io
    description:
    - A list of base URL(s) to retrieve C(update-center.json), and direct plugin files
      from.
    - This can be a list since community.general 3.3.0.
    elements: str
    type: list

jenkins_home:
    default: /var/lib/jenkins
    description:
    - Home directory of the Jenkins user.
    type: path

url_password:
    description:
    - The password for use in HTTP basic authentication.
    - If the O(url_username) parameter is not specified, the O(url_password) parameter
      will not be used.
    type: str

url_username:
    description:
    - The username for use in HTTP basic authentication.
    - This parameter can be used without O(url_password) for sites that allow empty passwords
    type: str

unsafe_writes:
    default: false
    description:
    - Influence when to use atomic operation to prevent data corruption or inconsistent
      reads from the target filesystem object.
    - By default this module uses atomic operations to prevent data corruption or inconsistent
      reads from the target filesystem objects, but sometimes systems are configured or
      just broken in ways that prevent this. One example is docker mounted filesystem
      objects, which cannot be updated atomically from inside the container and can only
      be written in an unsafe manner.
    - This option allows Ansible to fall back to unsafe methods of updating filesystem
      objects when atomic operations fail (however, it doesn't force Ansible to perform
      unsafe writes).
    - IMPORTANT! Unsafe writes are subject to race conditions and can lead to data corruption.
    type: bool
    version_added: '2.2'
    version_added_collection: ansible.builtin

validate_certs:
    default: true
    description:
    - If V(no), SSL certificates will not be validated.
    - This should only be used on personally controlled sites using self-signed certificates.
    type: bool

force_basic_auth:
    default: false
    description:
    - Credentials specified with O(url_username) and O(url_password) should be passed
      in HTTP Header.
    type: bool

with_dependencies:
    default: true
    description:
    - Defines whether to install plugin dependencies.
    - This option takes effect only if the O(version) is not defined.
    type: bool

updates_expiration:
    default: 86400
    description:
    - Number of seconds after which a new copy of the C(update-center.json) file is downloaded.
      This is used to avoid the need to download the plugin to calculate its checksum
      when O(state=latest) is specified.
    - Set it to V(0) if no cache file should be used. In that case, the plugin file will
      always be downloaded to calculate its checksum when O(state=latest) is specified.
    type: int

update_json_url_segment:
    default:
    - update-center.json
    - updates/update-center.json
    description:
    - A list of URL segment(s) to retrieve the update center json file from.
    elements: str
    type: list
    version_added: 3.3.0
    version_added_collection: community.general

latest_plugins_url_segments:
    default:
    - latest
    description:
    - Path inside the O(updates_url) to get latest plugins from.
    elements: str
    type: list
    version_added: 3.3.0
    version_added_collection: community.general

versioned_plugins_url_segments:
    default:
    - download/plugins
    - plugins
    description:
    - Path inside the O(updates_url) to get specific version of plugins from.
    elements: str
    type: list
    version_added: 3.3.0
    version_added_collection: community.general

Outputs

plugin:
  description: plugin name
  returned: success
  sample: build-pipeline-plugin
  type: str
state:
  description: state of the target, after execution
  returned: success
  sample: present
  type: str