community.general.jira (8.5.0) — module

Create and modify issues in a JIRA instance

Authors: Steve Smith (@tarka), Per Abildgaard Toft (@pertoft), Brandon McNama (@DWSR)

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

Create and modify issues in a JIRA instance.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.

# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a unix account for the reporter
  become: true
  user:
    name: '{{ issue.meta.fields.creator.name }}'
    comment: '{{ issue.meta.fields.creator.displayName }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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.
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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

Inputs

    
jql:
    description:
    - Query JIRA in JQL Syntax, e.g. 'CMDB Hostname'='test.example.com'.
    required: false
    type: str
    version_added: 0.2.0
    version_added_collection: community.general

uri:
    description:
    - Base URI for the JIRA instance.
    required: true
    type: str

issue:
    aliases:
    - ticket
    description:
    - An existing issue key to operate on.
    required: false
    type: str

token:
    description:
    - The personal access token to log-in with.
    - Mutually exclusive with O(username) and O(password).
    type: str
    version_added: 4.2.0
    version_added_collection: community.general

fields:
    default: {}
    description:
    - This is a free-form data structure that can contain arbitrary data. This is passed
      directly to the JIRA REST API (possibly after merging with other required data,
      as when passed to create). See examples for more information, and the JIRA REST
      API for the structure required for various fields.
    - When passed to comment, the data structure is merged at the first level since community.general
      4.6.0. Useful to add JIRA properties for example.
    - Note that JIRA may not allow changing field values on specific transitions or states.
    required: false
    type: dict

status:
    description:
    - Only used when O(operation) is V(transition), and a bit of a misnomer, it actually
      refers to the transition name.
    required: false
    type: str

comment:
    description:
    - The comment text to add.
    - Note that JIRA may not allow changing field values on specific transitions or states.
    required: false
    type: str

project:
    description:
    - The project for this operation. Required for issue creation.
    required: false
    type: str

summary:
    description:
    - The issue summary, where appropriate.
    - Note that JIRA may not allow changing field values on specific transitions or states.
    required: false
    type: str

timeout:
    default: 10
    description:
    - Set timeout, in seconds, on requests to JIRA API.
    required: false
    type: float

assignee:
    description:
    - Sets the the assignee when O(operation) is V(create), V(transition), or V(edit).
    - Recent versions of JIRA no longer accept a user name as a user identifier. In that
      case, use O(account_id) instead.
    - Note that JIRA may not allow changing field values on specific transitions or states.
    required: false
    type: str

linktype:
    description:
    - Set type of link, when action 'link' selected.
    required: false
    type: str

password:
    description:
    - The password to log-in with.
    - Must be used with O(username).  Mutually exclusive with O(token).
    type: str

username:
    description:
    - The username to log-in with.
    - Must be used with O(password). Mutually exclusive with O(token).
    type: str

issuetype:
    description:
    - The issue type, for issue creation.
    required: false
    type: str

operation:
    aliases:
    - command
    choices:
    - attach
    - comment
    - create
    - edit
    - fetch
    - link
    - search
    - transition
    - update
    - worklog
    description:
    - The operation to perform.
    - V(worklog) was added in community.general 6.5.0.
    required: true
    type: str

account_id:
    description:
    - Sets the account identifier for the assignee when O(operation) is V(create), V(transition),
      or V(edit).
    - Note that JIRA may not allow changing field values on specific transitions or states.
    type: str
    version_added: 2.5.0
    version_added_collection: community.general

attachment:
    description:
    - Information about the attachment being uploaded.
    suboptions:
      content:
        description:
        - The Base64 encoded contents of the file to attach. If not specified, the contents
          of O(attachment.filename) will be used instead.
        type: str
      filename:
        description:
        - The path to the file to upload (from the remote node) or, if O(attachment.content)
          is specified, the filename to use for the attachment.
        required: true
        type: path
      mimetype:
        description:
        - The MIME type to supply for the upload. If not specified, best-effort detection
          will be done.
        type: str
    type: dict
    version_added: 2.5.0
    version_added_collection: community.general

maxresults:
    description:
    - Limit the result of O(operation=search). If no value is specified, the default jira
      limit will be used.
    - Used when O(operation=search) only, ignored otherwise.
    required: false
    type: int
    version_added: 0.2.0
    version_added_collection: community.general

description:
    description:
    - The issue description, where appropriate.
    - Note that JIRA may not allow changing field values on specific transitions or states.
    required: false
    type: str

inwardissue:
    description:
    - Set issue from which link will be created.
    required: false
    type: str

outwardissue:
    description:
    - Set issue to which link will be created.
    required: false
    type: str

validate_certs:
    default: true
    description:
    - Require valid SSL certificates (set to V(false) if you would like to use self-signed
      certificates)
    required: false
    type: bool

comment_visibility:
    description:
    - Used to specify comment comment visibility.
    - See U(https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-comments/#api-rest-api-2-issue-issueidorkey-comment-post)
      for details.
    suboptions:
      type:
        choices:
        - group
        - role
        description:
        - Use type to specify which of the JIRA visibility restriction types will be used.
        required: true
        type: str
      value:
        description:
        - Use value to specify value corresponding to the type of visibility restriction.
          For example name of the group or role.
        required: true
        type: str
    type: dict
    version_added: 3.2.0
    version_added_collection: community.general