community.general.jenkins_plugin 模块 – 添加或删除 Jenkins 插件
注意
此模块是 community.general 集合(版本 10.1.0)的一部分。
如果您使用的是 ansible
包,您可能已经安装了此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install community.general
。
要在剧本中使用它,请指定:community.general.jenkins_plugin
。
概要
Ansible 模块,用于帮助管理 Jenkins 插件。
参数
参数 |
注释 |
---|---|
结果文件系统对象应具有的属性。 要获取支持的标志,请查看目标系统上 此字符串应包含与 默认情况下假定使用 |
|
用于 SSL 客户端身份验证的 PEM 格式证书链文件。 此文件还可以包括密钥,如果包含密钥,则不需要 |
|
包含用于 SSL 客户端身份验证的私钥的 PEM 格式文件。 如果 |
|
如果 选择
|
|
操作系统上 Jenkins 组的 GID 或名称。 默认: |
|
要标识为的标头,通常出现在 Web 服务器日志中。 默认: |
|
Jenkins 用户的 home 目录。 默认: |
|
默认: |
|
应用于版本化插件的文件模式。 默认: |
|
插件名称。 |
|
操作系统上 Jenkins 用户的 UID 或名称。 默认: |
|
SELinux 文件系统对象上下文的级别部分。 这是 MLS/MCS 属性,有时称为 设置为 |
|
SELinux 文件系统对象上下文的角色部分。 设置为 |
|
SELinux 文件系统对象上下文的类型部分。 设置为 |
|
SELinux 文件系统对象上下文的用户部分。 默认情况下,它在适用的情况下使用 当设置为 |
|
期望的插件状态。 如果设置为 选择
|
|
服务器连接超时时间,单位为秒。 默认值: |
|
影响何时使用原子操作,以防止数据损坏或从目标文件系统对象读取不一致的数据。 默认情况下,此模块使用原子操作来防止数据损坏或从目标文件系统对象读取不一致的数据,但有时系统配置或仅仅是损坏的方式会阻止这种情况。一个例子是 Docker 挂载的文件系统对象,这些对象无法从容器内部以原子方式更新,只能以不安全的方式写入。 当原子操作失败时,此选项允许 Ansible 回退到不安全的文件系统对象更新方法(但是,它不会强制 Ansible 执行不安全的写入)。 重要提示!不安全的写入会受到竞争条件的影响,并可能导致数据损坏。 选择
|
|
用于从中检索更新中心 JSON 文件的一个或多个 URL 段的列表。 默认值: |
|
下载新的 如果不需要使用缓存文件,请将其设置为 默认值: |
|
用于检索 自 community.general 3.3.0 起,这可以是一个列表。 默认值: |
|
Jenkins 服务器的 URL。 默认值: |
|
用于 HTTP 基本身份验证的密码。 如果未指定 |
|
用于 HTTP 基本身份验证的用户名。 对于允许空密码的站点,可以使用此参数,而无需 |
|
使用 GSSAPI 执行身份验证,通常用于 Kerberos 或通过协商进行 Kerberos 身份验证。 需要安装 Python 库 gssapi。 GSSAPI 的凭据可以使用 即使已安装 NTLM 的 GSSAPI 机制,也 不 支持 NTLM 身份验证。 选择
|
|
如果为 选择
|
|
如果为 这只应在个人控制的使用自签名证书的站点上使用。 选择
|
|
插件版本号。 如果指定此选项,则必须手动安装所有插件依赖项。 验证是否安装了正确的版本可能需要更长的时间。如果指定了特定的版本号,则尤其如此。 引用版本以防止该值被解释为浮点数。例如,如果 |
|
在 默认值: |
|
属性
属性 |
支持 |
描述 |
---|---|---|
支持: 完整 |
可以在 |
|
支持: 无 |
当处于 diff 模式时,将返回有关已更改(或可能需要在 |
注释
注意
插件安装应在 root 或磁盘上拥有插件文件的同一用户下运行。仅当插件尚未安装且未指定版本时,才会执行 API 安装,这只需要 Web UI 凭据。
有必要通知处理程序或调用 ansible.builtin.service 模块,以便在新插件安装后重新启动 Jenkins 服务。
仅当插件已安装并且在插件安装后 Jenkins 服务已成功重新启动时,固定才有效。
无法通过更改
url
参数以指向 Jenkins 服务器来远程运行模块。该模块必须在运行 Jenkins 的主机上使用,因为它需要直接访问插件文件。
示例
- name: Install plugin
community.general.jenkins_plugin:
name: build-pipeline-plugin
- name: Install plugin without its dependencies
community.general.jenkins_plugin:
name: build-pipeline-plugin
with_dependencies: false
- name: Make sure the plugin is always up-to-date
community.general.jenkins_plugin:
name: token-macro
state: latest
- name: Install specific version of the plugin
community.general.jenkins_plugin:
name: token-macro
version: "1.15"
- name: Pin the plugin
community.general.jenkins_plugin:
name: token-macro
state: pinned
- name: Unpin the plugin
community.general.jenkins_plugin:
name: token-macro
state: unpinned
- name: Enable the plugin
community.general.jenkins_plugin:
name: token-macro
state: enabled
- name: Disable the plugin
community.general.jenkins_plugin:
name: token-macro
state: disabled
- name: Uninstall plugin
community.general.jenkins_plugin:
name: build-pipeline-plugin
state: absent
#
# Example of how to authenticate
#
- name: Install plugin
community.general.jenkins_plugin:
name: build-pipeline-plugin
url_username: admin
url_password: p4ssw0rd
url: https://127.0.0.1:8888
#
# 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
#
# 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: https://127.0.0.1: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 }}"
返回值
常见的返回值记录在 这里,以下是此模块独有的字段
键 |
描述 |
---|---|
插件名称 返回: 成功 示例: |
|
执行后目标的状态 返回: 成功 示例: |