ansible / ansible.builtin / v2.4.3.0-1 / module / jenkins_plugin Add or remove Jenkins plugin | "added in version" 2.2 of ansible.builtin" Authors: Jiri Tyr (@jtyr) preview | supported by communityansible.builtin.jenkins_plugin (v2.4.3.0-1) — module
pip
Install with pip install ansible==2.4.3.0.post1
Ansible module which helps to manage Jenkins plugins.
- name: Install plugin jenkins_plugin: name: build-pipeline-plugin
- name: Install plugin without its dependencies jenkins_plugin: name: build-pipeline-plugin with_dependencies: no
- name: Make sure the plugin is always up-to-date jenkins_plugin: name: token-macro state: latest
- name: Install specific version of the plugin jenkins_plugin: name: token-macro version: "1.15"
- name: Pin the plugin jenkins_plugin: name: token-macro state: pinned
- name: Unpin the plugin jenkins_plugin: name: token-macro state: unpinned
- name: Enable the plugin jenkins_plugin: name: token-macro state: enabled
- name: Disable the plugin jenkins_plugin: name: token-macro state: disabled
- name: Uninstall plugin jenkins_plugin: name: build-pipeline-plugin state: absent
# # Example of how to authenticate # # my_jenkins_params: # url_username: admin # - name: Install plugin jenkins_plugin: name: build-pipeline-plugin params: "{{ my_jenkins_params }}" url_password: p4ssw0rd url: http://localhost:8888
# Note that url_password **can not** be placed in params as params could end up in a log file # # 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: yes build-pipeline-plugin: version: "1.4.9" pinned: no enabled: yes tasks: - name: Install plugins without a specific version 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 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 set_fact: jenkins_restart_required: no - name: Check if restart is required by any of the versioned plugins set_fact: jenkins_restart_required: yes when: item.changed with_items: "{{ my_jenkins_plugin_versioned.results }}" - name: Check if restart is required by any of the unversioned plugins set_fact: jenkins_restart_required: yes when: item.changed with_items: "{{ my_jenkins_plugin_unversioned.results }}" - name: Restart Jenkins if required service: name: jenkins state: restarted when: jenkins_restart_required - name: Wait for Jenkins to start up 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 set_fact: jenkins_restart_required: no when: jenkins_restart_required - name: Plugin pinning 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 jenkins_plugin: name: "{{ item.key }}" state: "{{ 'enabled' if item.value['enabled'] else 'disabled'}}" when: > 'enabled' in item.value with_dict: "{{ my_jenkins_plugins }}"
url: default: http://localhost:8080 description: - URL of the Jenkins server. required: false mode: default: '0664' description: - File mode applied on versioned plugins. required: false name: description: - Plugin name. required: true group: default: jenkins description: - Name of the Jenkins group on the OS. required: false owner: default: jenkins description: - Name of the Jenkins user on the OS. required: false state: choices: - absent - present - pinned - unpinned - enabled - disabled - latest default: present description: - Desired plugin state. - If the C(latest) is set, the check for new version will be performed every time. This is suitable to keep the plugin up-to-date. required: false params: default: null description: - Option used to allow the user to overwrite any of the other options. To remove an option, set the value of the option to C(null). - Changed in 2.5.0, 2.4.1, 2.3.3 to raise an error if C(url_password) is specified in params. Use the actual C(url_password) argument instead. required: false timeout: default: 30 description: - Server connection timeout in secs. required: false version: default: null 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 C(1.20) would be unquoted, it would become C(1.2). required: false updates_url: default: https://updates.jenkins-ci.org description: - URL of the Update Centre. - Used as the base URL to download the plugins and the I(update-center.json) JSON file. required: false jenkins_home: default: /var/lib/jenkins description: - Home directory of the Jenkins user. required: false with_dependencies: choices: - 'yes' - 'no' default: 'yes' description: - Defines whether to install plugin dependencies. - This option takes effect only if the I(version) is not defined. required: false updates_expiration: default: 86400 description: - Number of seconds after which a new copy of the I(update-center.json) file is downloaded. This is used to avoid the need to download the plugin to calculate its checksum when C(latest) is specified. - Set it to C(0) if no cache file should be used. In that case, the plugin file will always be downloaded to calculate its checksum when C(latest) is specified. required: false
plugin: description: plugin name returned: success sample: build-pipeline-plugin type: string state: description: state of the target, after execution returned: success sample: present type: string