community.general.jira – create and modify issues in a JIRA instance

Note

This plugin is part of the community.general collection (version 1.3.2).

To install it use: ansible-galaxy collection install community.general.

To use it in a playbook, specify: community.general.jira.

Synopsis

  • Create and modify issues in a JIRA instance.

Parameters

Parameter Choices/Defaults Comments
assignee
string
Sets the assignee on create or transition operations. Note not all transitions will allow this.
comment
string
The comment text to add.
description
string
The issue description, where appropriate.
fields
dictionary
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.
inwardissue
string
Set issue from which link will be created.
issue
string
An existing issue key to operate on.

aliases: ticket
issuetype
string
The issue type, for issue creation.
jql
string
added in 0.2.0 of community.general
Query JIRA in JQL Syntax, e.g. 'CMDB Hostname'='test.example.com'.
linktype
string
Set type of link, when action 'link' selected.
maxresults
integer
added in 0.2.0 of community.general
Limit the result of operation=search. If no value is specified, the default jira limit will be used.
Used when operation=search only, ignored otherwise.
operation
string / required
    Choices:
  • comment
  • create
  • edit
  • fetch
  • link
  • search
  • transition
  • update
The operation to perform.

aliases: command
outwardissue
string
Set issue to which link will be created.
password
string / required
The password to log-in with.
project
string
The project for this operation. Required for issue creation.
status
string
The desired status; only relevant for the transition operation.
summary
string
The issue summary, where appropriate.
timeout
float
Default:
10
Set timeout, in seconds, on requests to JIRA API.
uri
string / required
Base URI for the JIRA instance.
username
string / required
The username to log-in with.
validate_certs
boolean
    Choices:
  • no
  • yes
Require valid SSL certificates (set to `false` if you'd like to use self-signed certificates)

Notes

Note

  • Currently this only works with basic-auth.

Examples

# 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

# 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 by target status
- name: Close the issue
  community.general.jira:
    uri: '{{ server }}'
    username: '{{ user }}'
    password: '{{ pass }}'
    issue: '{{ issue.meta.key }}'
    operation: transition
    status: Done
  args:
    fields:
      customfield_14321: [ {'set': {'value': 'Value of Select' }} ]
      comment:  [ { 'add': { 'body' : 'Test' } }]

Authors

  • Steve Smith (@tarka)
  • Per Abildgaard Toft (@pertoft)

© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.10/collections/community/general/jira_module.html