ansible jira comment section

42 views
Skip to first unread message

Ramesh AR

unread,
Jan 13, 2021, 7:07:50 PM1/13/21
to Ansible Project
Hi, 

I have a playbook to retrieve user details and getting the output by using debug module. on same playbook second task to comment the user details in JIRA ticket. 

any idea how to redirect the debug output to jira module . 

- debug:
      msg: "{{ user | list | to_yaml }}"

  - name: Commenting output to Jira
    hosts: 127.0.0.1
    connection: local
    tasks:
    - name: Comment on issue
      jira:
       uri: 'https://xxxxx'
       username: 'xxxx'
       password: 'xxxx'
       issue: 'xxxx'
       operation: comment
       comment: "{{ user | list | to_yaml }}" >>> i tried this way but didn't work
     delegate_to: localhost 

Thank you,
Ramesh 

Dick Visser

unread,
Jan 14, 2021, 2:32:01 AM1/14/21
to ansible...@googlegroups.com
What does that "user" variable look like?
What does "didn't work" mean exactly?


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a0c47ffb-7a28-49f7-8000-022199a92b75n%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Abhijeet Kasurde

unread,
Jan 14, 2021, 3:18:46 AM1/14/21
to ansible...@googlegroups.com
Are you getting error messages? I am able to process the comment

- name: Comment an issue
community.general.jira:
uri: '{{ jirauri }}'
username: '{{ jira_username }}'
password: "{{ lookup('file', '/Users/akasurde/.jira_api_token') }}"
project: scrum-project
operation: comment
issue: "SP-1"
comment: "In Progress"
register: issue_comment

- debug:
msg: "{{ issue_comment }}"



"meta": {
            "author": {
                "accountId": "557079:f1799ad8-ab63-413a-a052-4e0cb738dfa9",
                "accountType": "atlassian",
                "active": true,
                "avatarUrls": {},
                "displayName": "Aab",
                "emailAddress": "x...@gmail.com",
                "self": "https://ansi.atlassian.net/rest/api/2/user?accountId=557058%3Af1799ad8-ab63-413a-a052-4e0cb738dfa9",
                "timeZone": "Asia/Kolkata"
            },
            "body": "In Progress",
            "created": "2021-01-14T13:44:12.521+0530",
            "id": "10000",
            "jsdPublic": true,
            "self": "https://ansi.atlassian.net/rest/api/2/issue/10000/comment/10000",
            "updateAuthor": {
                "accountId": "557079:f1799ad8-ab63-413a-a052-4e0cb738dfa9",
                "accountType": "atlassian",
                "active": true,
                "avatarUrls": {
                },
                "displayName": "aab",
                "emailAddress": "x...@gmail.com",
                "self": "https://ansi.atlassian.net/rest/api/2/user?accountId=557058%3Af1799ad8-ab63-413a-a052-4e0cb738dfa9",
                "timeZone": "Asia/Kolkata"
            }
            }




--
Thanks,
Abhijeet Kasurde

Ramesh AR

unread,
Jan 14, 2021, 1:26:47 PM1/14/21
to Ansible Project
HI Dick / Abhijeet,

I want to pass the below variable data's to Jira comment section . 

TASK [debug] *************************************************************************************************************************************
ok: [test1] => {}

MSG:

- {accountStatus: active, id: '1', name: admin, priv: admin}
- {accountStatus: active, id: '2', name: VE, priv: admin}
- {accountStatus: active, id: '3', name: RIOR, priv: admin}
- {accountStatus: active, id: '4', name: VPIO, priv: admin}
- {accountStatus: active, id: '5', name: vie, priv: admin}
- {accountStatus: active, id: '6', name: p5work, priv: admin}
- {accountStatus: active, id: '7', name: DEU, priv: admin}

+++++++++++++++++++++++++++++++++++++++++++
 - set_fact:
      user: "{{ result.configResolveClass.children|json_query(my_query) }}"
    vars:
      my_query: "[].outConfigs.children[].aaaUser.attributes[].{id: id, name: name, priv: priv, accountStatus: accountStatus}"
  - debug:
      msg: "{{ user | rejectattr('accountStatus', 'eq', 'inactive')| list | to_yaml }}"
++++++++++++++++++++++++++++++++++++++++++++

Thanks,
Ramesh

Ramesh AR

unread,
Jan 14, 2021, 3:35:21 PM1/14/21
to Ansible Project
I'm able to comment the debug output but there's no host/IP details.. is there any way to take and comment as well . ?

Now: commenting below format,

 {accountStatus: active, id: '1', name: admin, priv: admin}
- {accountStatus: active, id: '2', name: VE, priv: admin}
- {accountStatus: active, id: '3', name: RIOR, priv: admin}
- {accountStatus: active, id: '4', name: VPIO, priv: admin}
- {accountStatus: active, id: '5', name: vie, priv: admin}
- {accountStatus: active, id: '6', name: p5work, priv: admin}
- {accountStatus: active, id: '7', name: DEU, priv: admin}

expecting comment: should be with hostname / IP address

ok: [test1] => {}

MSG:

- {accountStatus: active, id: '1', name: admin, priv: admin}
- {accountStatus: active, id: '2', name: VE, priv: admin}
- {accountStatus: active, id: '3', name: RIOR, priv: admin}
- {accountStatus: active, id: '4', name: VPIO, priv: admin}
- {accountStatus: active, id: '5', name: vie, priv: admin}
- {accountStatus: active, id: '6', name: p5work, priv: admin}
- {accountStatus: active, id: '7', name: DEU, priv: admin}



Dick Visser

unread,
Jan 14, 2021, 5:31:39 PM1/14/21
to ansible...@googlegroups.com
Correct. You didn't mention that at all, nor how that data looks like, nor where it comes from.

Message has been deleted

Ramesh AR

unread,
Jan 14, 2021, 6:05:48 PM1/14/21
to Ansible Project
Hi Dick,

Sure, Let me provide complete playbook  . 

---
- hosts: cimc
  connection: local
  gather_facts: no
  tasks:
  - name: Checking Local Users
    imc_rest:
      hostname: "{{ imc_hostname }}"
      username: "{{ imc_username }}"
      password: "{{ imc_password }}"
      protocol: https
      timeout: 60
      validate_certs: no
      content: |
         <configResolveClass inHierarchical="false" classId="aaaUser"/>
    register: result
  - set_fact:
      user: "{{ result.configResolveClass.children|json_query(my_query) }}"
    vars:
      my_query: "[].outConfigs.children[].aaaUser.attributes[].{id: id, name: name, priv: priv, accountStatus: accountStatus}"
  - debug:
      msg: "{{ user | rejectattr('accountStatus', 'eq', 'inactive')| list | to_yaml }}"

  - name: Comment on issue
    jira:
      uri: 'XXXX'
      username: 'XXXX'
      password: 'XXXX'
      issue: 'XXXX'
      operation: comment
      comment: "{{ user | rejectattr('accountStatus', 'eq', 'inactive')| list | to_yaml }}"
    delegate_to: localhost



PLAY [cimc] ********************************************************************************************************************************

TASK [Checking Local Users] **********************************************************************************************************************
ok: [Host1]

TASK [set_fact] **********************************************************************************************************************************
ok: [Host1]

TASK [debug] *************************************************************************************************************************************
ok: [Host1] => {}

MSG:

- {accountStatus: active, id: '1', name: admin, priv: admin}
- {accountStatus: active, id: '2', name: xyz, priv: admin}
- {accountStatus: active, id: '3', name: xyz, priv: admin}
- {accountStatus: active, id: '4', name: xyz, priv: admin}
- {accountStatus: active, id: '5', name: xyz, priv: admin}
- {accountStatus: active, id: '6', name: xyz, priv: read-only}
- {accountStatus: active, id: '7', name: xyz, priv: read-only}


TASK [Comment on issue] **************************************************************************************************************************
changed: [Host1 -> localhost]

PLAY RECAP ***************************************************************************************************************************************
Host1             : ok=4    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

jira module adding only the data's without the Host1,  not sure where to modify to include the host inventory 


Thank you,
Ramesh 
Reply all
Reply to author
Forward
0 new messages