community.general.jira 模块 – 在 JIRA 实例中创建和修改问题
注意
此模块是 community.general 集合 (版本 10.1.0) 的一部分。
如果您使用的是 ansible 包,则您可能已经安装了此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install community.general。
要在 playbook 中使用它,请指定:community.general.jira。
概要
- 在 JIRA 实例中创建和修改问题。 
参数
| 参数 | 注释 | 
|---|---|
| 当  请注意,JIRA 可能不允许在特定转换或状态下更改字段值。 | |
| 当  最新版本的 JIRA 不再接受用户名作为用户标识符。在这种情况下,请改用  请注意,JIRA 可能不允许在特定转换或状态下更改字段值。 | |
| 有关正在上传的附件的信息。 | |
| 要附加的文件的 Base64 编码内容。如果未指定,则将使用  | |
| 要上传的文件的路径(来自远程节点),或者,如果指定了  | |
| 要为上传提供的 MIME 类型。如果未指定,将进行尽力而为的检测。 | |
| 要添加的评论文本。 请注意,JIRA 可能不允许在特定转换或状态下更改字段值。 | |
| 使用 type 指定将使用哪种 JIRA 可见性限制类型。 选项 
 | |
| 使用 value 指定与可见性限制类型对应的值。例如,组或角色的名称。 | |
| 问题描述(如果适用)。 请注意,JIRA 可能不允许在特定转换或状态下更改字段值。 | |
| 这是一个自由格式的数据结构,可以包含任意数据。这将直接传递给 JIRA REST API(可能在与其他必需数据合并后,例如传递给 create 时)。有关更多信息,请参见示例和 JIRA REST API 以了解各种字段所需的结构。 传递给 comment 时,自 community.general 4.6.0 起,数据结构在第一层合并。例如,用于添加 JIRA 属性。 请注意,JIRA 可能不允许在特定转换或状态下更改字段值。 默认值:  | |
| 设置将从中创建链接的问题。 | |
| 要操作的现有问题密钥。 | |
| 问题类型,用于创建问题。 | |
| 以 JQL 语法查询 JIRA,例如 ‘CMDB Hostname’=’test.example.com’。 | |
| 选择操作“link”时设置链接类型。 | |
| 限制  仅在  | |
| 要执行的操作。 
 选项 
 | |
| 设置将向其创建链接的问题。 | |
| 此操作的项目。创建问题时必需。 | |
| 仅当 | |
| 问题概要(如果适用)。 请注意,JIRA 可能不允许在特定转换或状态下更改字段值。 | |
| 设置对 JIRA API 请求的超时时间(秒)。 默认值:  | |
| JIRA 实例的基本 URI。 | |
| 需要有效的 SSL 证书(如果要使用自签名证书,请设置为 选项 
 | 
属性
| 属性 | 支持 | 描述 | 
|---|---|---|
| 支持:不支持 | 可以在 | |
| 支持:不支持 | 在 diff 模式下,将返回有关已更改内容(或可能需要在 | 
备注
示例
# Create a new issue and add a comment to it:
- name: Create an issue
  community.general.jira:
    uri: '{{ server }}'
    username: '{{ user }}'
    password: '{{ pass }}'
    project: ANS
    operation: create
    summary: Example Issue
    description: Created using Ansible
    issuetype: Task
  args:
    fields:
        customfield_13225: "test"
        customfield_12931: {"value": "Test"}
  register: issue
- name: Comment on issue
  community.general.jira:
    uri: '{{ server }}'
    username: '{{ user }}'
    password: '{{ pass }}'
    issue: '{{ issue.meta.key }}'
    operation: comment
    comment: A comment added by Ansible
- name: Comment on issue with restricted visibility
  community.general.jira:
    uri: '{{ server }}'
    username: '{{ user }}'
    password: '{{ pass }}'
    issue: '{{ issue.meta.key }}'
    operation: comment
    comment: A comment added by Ansible
    comment_visibility:
      type: role
      value: Developers
- name: Comment on issue with property to mark it internal
  community.general.jira:
    uri: '{{ server }}'
    username: '{{ user }}'
    password: '{{ pass }}'
    issue: '{{ issue.meta.key }}'
    operation: comment
    comment: A comment added by Ansible
    fields:
      properties:
        - key: 'sd.public.comment'
          value:
            internal: true
# Add an workog to an existing issue
- name: Worklog on issue
  community.general.jira:
    uri: '{{ server }}'
    username: '{{ user }}'
    password: '{{ pass }}'
    issue: '{{ issue.meta.key }}'
    operation: worklog
    comment: A worklog added by Ansible
    fields:
      timeSpentSeconds: 12000
- name: Workflow on issue with comment restricted visibility
  community.general.jira:
    uri: '{{ server }}'
    username: '{{ user }}'
    password: '{{ pass }}'
    issue: '{{ issue.meta.key }}'
    operation: worklog
    comment: A worklog added by Ansible
    comment_visibility:
      type: role
      value: Developers
    fields:
      timeSpentSeconds: 12000
- name: Workflow on issue with comment property to mark it internal
  community.general.jira:
    uri: '{{ server }}'
    username: '{{ user }}'
    password: '{{ pass }}'
    issue: '{{ issue.meta.key }}'
    operation: worklog
    comment: A worklog added by Ansible
    fields:
      properties:
        - key: 'sd.public.comment'
          value:
            internal: true
      timeSpentSeconds: 12000
# Assign an existing issue using edit
- name: Assign an issue using free-form fields
  community.general.jira:
    uri: '{{ server }}'
    username: '{{ user }}'
    password: '{{ pass }}'
    issue: '{{ issue.meta.key}}'
    operation: edit
    assignee: ssmith
# Create an issue with an existing assignee
- name: Create an assigned issue
  community.general.jira:
    uri: '{{ server }}'
    username: '{{ user }}'
    password: '{{ pass }}'
    project: ANS
    operation: create
    summary: Assigned issue
    description: Created and assigned using Ansible
    issuetype: Task
    assignee: ssmith
# Edit an issue
- name: Set the labels on an issue using free-form fields
  community.general.jira:
    uri: '{{ server }}'
    username: '{{ user }}'
    password: '{{ pass }}'
    issue: '{{ issue.meta.key }}'
    operation: edit
  args:
    fields:
        labels:
          - autocreated
          - ansible
# Updating a field using operations: add, set & remove
- name: Change the value of a Select dropdown
  community.general.jira:
    uri: '{{ server }}'
    username: '{{ user }}'
    password: '{{ pass }}'
    issue: '{{ issue.meta.key }}'
    operation: update
  args:
    fields:
      customfield_12931: [ {'set': {'value': 'Virtual'}} ]
      customfield_13820: [ {'set': {'value':'Manually'}} ]
  register: cmdb_issue
  delegate_to: localhost
# Retrieve metadata for an issue and use it to create an account
- name: Get an issue
  community.general.jira:
    uri: '{{ server }}'
    username: '{{ user }}'
    password: '{{ pass }}'
    project: ANS
    operation: fetch
    issue: ANS-63
  register: issue
# Search for an issue
# You can limit the search for specific fields by adding optional args. Note! It must be a dict, hence, lastViewed: null
- name: Search for an issue
  community.general.jira:
    uri: '{{ server }}'
    username: '{{ user }}'
    password: '{{ pass }}'
    project: ANS
    operation: search
    maxresults: 10
    jql: project=cmdb AND cf[13225]="test"
  args:
    fields:
      lastViewed: null
  register: issue
- name: Create a unix account for the reporter
  become: true
  user:
    name: '{{ issue.meta.fields.creator.name }}'
    comment: '{{ issue.meta.fields.creator.displayName }}'
# You can get list of valid linktypes at /rest/api/2/issueLinkType
# url of your jira installation.
- name: Create link from HSP-1 to MKY-1
  community.general.jira:
    uri: '{{ server }}'
    username: '{{ user }}'
    password: '{{ pass }}'
    operation: link
    linktype: Relates
    inwardissue: HSP-1
    outwardissue: MKY-1
# Transition an issue
- name: Resolve the issue
  community.general.jira:
    uri: '{{ server }}'
    username: '{{ user }}'
    password: '{{ pass }}'
    issue: '{{ issue.meta.key }}'
    operation: transition
    status: Resolve Issue
    account_id: 112233445566778899aabbcc
    fields:
      resolution:
        name: Done
      description: I am done! This is the last description I will ever give you.
# Attach a file to an issue
- name: Attach a file
  community.general.jira:
    uri: '{{ server }}'
    username: '{{ user }}'
    password: '{{ pass }}'
    issue: HSP-1
    operation: attach
    attachment:
      filename: topsecretreport.xlsx
