ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
784 stars 1.45k forks source link

Jira module interacting with a Jira Servicedesk api? #8362

Open cidrbl0ck opened 1 month ago

cidrbl0ck commented 1 month ago

Summary

I am following the examples listed here, in order to create a new Issue in our Projects service desk. Except defining uri as: https://comapny.atlassian.net/ results in ret/api/2/issue being appended to the uri value. The correct uri for the service desk api is /rest/servicedeskapi/request.

Is this module not intended for this sort of use or is there a way to overwrite or define the entire uri value?

Issue Type

Bug Report

Component Name

community.general.jira

Ansible Version

$ ansible --version
bash-5.2# ansible --version
ansible [core 2.16.3]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.12/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.12.1 (main, Dec 18 2023, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)] (/usr/bin/python3)
  jinja version = 3.1.3
  libyaml = True
bash-5.2# 

Community.general Version

$ ansible-galaxy collection list community.general
# /root/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 8.6.0  

Configuration

$ ansible-config dump --only-changed
bash-5.2# ansible-config dump --only-changed
ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = False
CONFIG_FILE() = None

OS / Environment

ghcr.io/ansible/creator-ee:v24

Based off quay.io/fedora/fedora-minimal:39

Steps to Reproduce

---
- name: Creating service Issues in Jira
  gather_facts: false
  hosts: localhost
  connection: local
  vars:
    jira_user: "{{ lookup('env', 'JIRA_USER') }}"
    jira_pass: "{{ lookup('env', 'JIRA_PASS') }}"
    jira_host: "{{ lookup('env', 'JIRA_HOST') }}"

  tasks:
    - name: Create a new Issue in Jira
      community.general.jira:
        uri: "{{ jira_host }}"
        username: "{{ jira_user }}"
        password: "{{ jira_pass }}"
        project: "EISD"
        operation: create
        summary: "Test Service Request"
        description: "Test Service Request"
        issuetype: "Service Request"
      register: result
      ignore_errors: true

    - name: Print the result
      debug:
        var: result

Export JIRA_HOST, JIRA_USER and JIRA_PASS with the appropriate values.

Expected Results

A new issue created.

Actual Results

bash-5.2# /usr/local/bin/ansible-playbook /workspaces/aap/sysops-aap/aap-jira-createINC.yml -vvvv
ansible-playbook [core 2.16.3]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.12/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.12.1 (main, Dec 18 2023, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)] (/usr/bin/python3)
  jinja version = 3.1.3
  libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from 
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
Loading collection community.general from /root/.ansible/collections/ansible_collections/community/general
Loading callback plugin default of type stdout, v2.0 from /usr/local/lib/python3.12/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: aap-jira-createINC.yml ***********************************************************************************************************************
Positional arguments: /workspaces/aap/sysops-aap/aap-jira-createINC.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('/etc/ansible/hosts',)
forks: 5
1 plays in /workspaces/aap/sysops-aap/aap-jira-createINC.yml

PLAY [Creating service Issues in Jira] *****************************************************************************************************************

TASK [Create a new Issue in Jira] **********************************************************************************************************************
task path: /workspaces/aap/sysops-aap/aap-jira-createINC.yml:14
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~root && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1715712111.932311-44111-221119441651739 `" && echo ansible-tmp-1715712111.932311-44111-221119441651739="` echo /root/.ansible/tmp/ansible-tmp-1715712111.932311-44111-221119441651739 `" ) && sleep 0'
Using module file /root/.ansible/collections/ansible_collections/community/general/plugins/modules/jira.py
<127.0.0.1> PUT /root/.ansible/tmp/ansible-local-43875ilnfp71c/tmp3ak9yzti TO /root/.ansible/tmp/ansible-tmp-1715712111.932311-44111-221119441651739/AnsiballZ_jira.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1715712111.932311-44111-221119441651739/ /root/.ansible/tmp/ansible-tmp-1715712111.932311-44111-221119441651739/AnsiballZ_jira.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1715712111.932311-44111-221119441651739/AnsiballZ_jira.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1715712111.932311-44111-221119441651739/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_community.general.jira_payload_7qq0q8_8/ansible_community.general.jira_payload.zip/ansible_collections/community/general/plugins/modules/jira.py", line 784, in request
KeyError: 'body'
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "account_id": null,
            "assignee": null,
            "attachment": null,
            "comment": null,
            "comment_visibility": null,
            "description": "Test Service Request",
            "fields": {},
            "inwardissue": null,
            "issue": null,
            "issuetype": "Service Request",
            "jql": null,
            "linktype": null,
            "maxresults": null,
            "operation": "create",
            "outwardissue": null,
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "project": "EISD",
            "status": null,
            "summary": "Test Service Request",
            "timeout": 10.0,
            "token": null,
            "uri": "https://xxx.atlassian.net",
            "username": "svc-jira@xxx.com",
            "validate_certs": true
        }
    },
    "msg": "The request \"POST https://xxx.atlassian.net/rest/api/2/issue/\" returned the unexpected status code -1 Request failed: <urlopen error [Errno 99] Cannot assign requested address>\nNone"
}
...ignoring

TASK [Print the result] ********************************************************************************************************************************
task path: /workspaces/aap/sysops-aap/aap-jira-createINC.yml:27
ok: [localhost] => {
    "result": {
        "changed": false,
        "exception": "Traceback (most recent call last):\n  File \"/tmp/ansible_community.general.jira_payload_7qq0q8_8/ansible_community.general.jira_payload.zip/ansible_collections/community/general/plugins/modules/jira.py\", line 784, in request\nKeyError: 'body'\n",
        "failed": true,
        "msg": "The request \"POST https://xxx.atlassian.net/rest/api/2/issue/\" returned the unexpected status code -1 Request failed: <urlopen error [Errno 99] Cannot assign requested address>\nNone"
    }
}

PLAY RECAP *********************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=1   

Code of Conduct

ansibullbot commented 1 month ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 1 month ago

cc @Slezhuk @pertoft @tarka click here for bot help

felixfontein commented 1 month ago

CC @russoz who worked on the module in the past and might know :)

russoz commented 1 month ago

hi @cidrbl0ck , sorry for taking this long.

If memory serves, JIRA Service Desk is not the same as plain old JIRA (or JIRA Software - they have gone through some rebranding a while back, not sure what the official names are today), so that would be the reason for the distinct URIs.

This module was created, back in the day, to interact with plain old Jira. Personally, I think it is a bit bloated and that we should break it in smaller pieces.

I know this is probably not the answer you would like to hear but right now I don't think there is much we can do. It will take a major revamp of the module, a comprehensive rewrite of everything to cover a meaningful set of APIs in both products.

cidrbl0ck commented 1 month ago

Thank you Alexi! For this current project I did end up rolling with plain old APi tasks. However I wonder, would it be possible for me to edit the ingrained uri? Or would that cause issues in other functions?

From: Alexei Znamensky @.> Date: Saturday, May 25, 2024 at 6:11 AM To: ansible-collections/community.general @.> Cc: Ben Hart @.>, Mention @.> Subject: Re: [ansible-collections/community.general] Jira module interacting with a Jira Servicedesk api? (Issue #8362)

hi @cidrbl0ckhttps://github.com/cidrbl0ck , sorry for taking this long.

If memory serves, JIRA Service Desk is not the same as plain old JIRA (or JIRA Software - they have gone through some rebranding a while back, not sure what the official names are today), so that would be the reason for the distinct URIs.

This module was created, back in the day, to interact with plain old Jira. Personally, I think it is a bit bloated and that we should break it in smaller pieces.

I know this is probably not the answer you would like to hear but right now I don't think there is much we can do. It will take a major revamp of the module, a comprehensive rewrite of everything to cover a meaningful set of APIs in both products.

— Reply to this email directly, view it on GitHubhttps://github.com/ansible-collections/community.general/issues/8362#issuecomment-2131186232, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AST3YYH6TO66CMHMUEQO5ALZEBPWJAVCNFSM6AAAAABHWYD3DCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZRGE4DMMRTGI. You are receiving this because you were mentioned.Message ID: @.***>

russoz commented 1 month ago

Thank you Alexi! For this current project I did end up rolling with plain old APi tasks. However I wonder, would it be possible for me to edit the ingrained uri? Or would that cause issues in other functions?

I would recommend creating a new, separate module for Jira Service Desk. As a matter of fact, I am considering breaking this module into smaller pieces, but no timeframe for that yet - I am doing exactly that with django_manage these days.