Ansible Playbook to Download Attachments from Several JIRA Tasks

Hello. I have a problem with looping in Ansible. The solution is probably simple. I just lack the knowledge and need some help.
Context.
We have a JIRA URL. It has a project DDI. My task at first was to download all attachments from a JIRA issue like this one. It is called “Refresh MO2 DDI” and its unique ID is KAN-63.

Here is the Ansible playbook that does the download just fine:

---
- name: Get all task metadata for the DCR project 
  hosts: localhost
  connection: local
  gather_facts: true
  vars_files:
    - vars/main.yml

  tasks:

    - name: Set fact for Ansible date_time | dcr_jira {{ ansible_date_time.iso8601 }}
      delegate_to: localhost
      run_once: true
      set_fact: 
        currentdate: "{{ ansible_date_time.date }}"
        tags: linux
          
    - name: Display Ansible date fact | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.debug:   
        var: currentdate
      run_once: true
      tags: linux   

    - name: Set Ansible current time fact | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.set_fact:
        current_time: "{{ now(fmt='%Y-%m-%d_%H-%M-%S') }}"
      run_once: true
      tags: linux

###############DOWNLOAD SECTION############################

    - name: Fetch Jira issue metadata | dcr_jira {{ ansible_date_time.iso8601 }}
      community.general.jira:
        uri: "{{ jira_url }}"
        username: "{{ jira_user }}"
        password: "{{ jira_api_token }}"
        operation: fetch
#        issue: "{{ issue_key }}"
        issue: KAN-83
      register: issue_data
      delegate_to: localhost

#    - name: Display DDI Refresh task unique Key
#      ansible.builtin.debug:   
#        var: issue_data

####################CODITIONALS DEBUG###################################

    - name: Set fact for task unique key | dcr_jira {{ ansible_date_time.iso8601 }}
      delegate_to: localhost
      run_once: true
      set_fact: 
        task_unique_key: "{{ issue_data.meta.key }}"
      tags: linux

    - name: Display DCR task unique Key | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.debug:   
        var: "{{ task_unique_key }}"

    - name: Display DCR Status | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.debug:   
        var: issue_data.meta.fields.status.name

    - name: Display DCR Assignee | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.debug:   
        var: issue_data.meta.fields.assignee.displayName

    - name: Display DCR Due Date | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.debug:   
        var: issue_data.meta.fields.duedate

    - name: Announce Task launch if DCR Status is in Implementation, Assigned to Automation and Due Date is today | dcr_jira {{ ansible_date_time.iso8601 }}
      debug:
        msg: "DCR Status has changed to 'In Progress', the Task is now assigned to 'Automation API' and Due Date is today. Proceeding with DCR tasks automation at {{ ansible_date_time.iso8601 }}."
      when: >
        "In Progress" in issue_data.meta.fields.status.name and 
        "Automation API" in issue_data.meta.fields.assignee.displayName and 
        "{{ now(fmt='%Y-%m-%d') }}" in issue_data.meta.fields.duedate

####################END OF CONDITIONALS DEBUG###########################

    - name: Run the DCR refresh conditional block to only execute when the conditions are met | dcr_jira {{ ansible_date_time.iso8601 }}
      block:

#        - name: Truncate the Ansible log
#          ansible.builtin.shell:
#            cmd: "truncate --s 0 /var/log/ansible/hosts/localhost"   

        - name: Download DCR SQL scripts to the server | dcr_jira {{ ansible_date_time.iso8601 }}
          ansible.builtin.get_url:
            url: "{{ item.content }}"
            dest: "{{ scratchpad_dcr_runtime }}/{{ item.filename }}"
            url_username: "{{ jira_user }}"
            url_password: "{{ jira_api_token }}"
            force_basic_auth: yes
            mode: '0644'
          loop: "{{ issue_data.meta.fields.attachment }}"
          when: issue_data.meta.fields.attachment is defined
          register: download_results

        - name: Display downloaded SQL scripts | dcr_jira {{ ansible_date_time.iso8601 }}
          ansible.builtin.debug:
            msg: "Downloaded: {{ item.dest }}"
          loop: "{{ download_results.results }}"
          when: item.changed

Here is the output:

[misoracle@ehsmg-mis-dba1 ansible]$ ap dcr.yml
[WARNING]: Found both group and host with same name: localhost
[WARNING]: Collection community.general does not support Ansible version 2.16.3

PLAY [Get all task metadata for the DCR project] ********************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************
ok: [localhost]

TASK [Set fact for Ansible date_time | dcr_jira 2026-05-05T14:51:25Z] ***********************************************************************************************************************************
ok: [localhost]

TASK [Display Ansible date fact | dcr_jira 2026-05-05T14:51:25Z] ****************************************************************************************************************************************
ok: [localhost] => {
    "currentdate": "2026-05-05"
}

TASK [Set Ansible current time fact | dcr_jira 2026-05-05T14:51:25Z] ************************************************************************************************************************************
ok: [localhost]

TASK [Fetch Jira issue metadata | dcr_jira 2026-05-05T14:51:25Z] ****************************************************************************************************************************************
ok: [localhost]

TASK [Set fact for task unique key | dcr_jira 2026-05-05T14:51:25Z] *************************************************************************************************************************************
ok: [localhost]

TASK [Display DCR task unique Key | dcr_jira 2026-05-05T14:51:25Z] **************************************************************************************************************************************
ok: [localhost] => {
    "KAN-83": "{{KAN-83}}"
}

TASK [Display DCR Status | dcr_jira 2026-05-05T14:51:25Z] ***********************************************************************************************************************************************
ok: [localhost] => {
    "issue_data.meta.fields.status.name": "In Progress"
}

TASK [Display DCR Assignee | dcr_jira 2026-05-05T14:51:25Z] *********************************************************************************************************************************************
ok: [localhost] => {
    "issue_data.meta.fields.assignee.displayName": "Automation API"
}

TASK [Display DCR Due Date | dcr_jira 2026-05-05T14:51:25Z] *********************************************************************************************************************************************
ok: [localhost] => {
    "issue_data.meta.fields.duedate": "2026-05-04"
}

TASK [Announce Task launch if DCR Status is in Implementation, Assigned to Automation and Due Date is today | dcr_jira 2026-05-05T14:51:25Z] ************************************************************
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: "In Progress" in issue_data.meta.fields.status.name and  "Automation API" in
issue_data.meta.fields.assignee.displayName and  "{{ now(fmt='%Y-%m-%d') }}" in issue_data.meta.fields.duedate
skipping: [localhost]

TASK [Download DCR SQL scripts to the server | dcr_jira 2026-05-05T14:51:25Z] ***************************************************************************************************************************
changed: [localhost] => (item={'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/10839', 'id': '10839', 'filename': 'DCR_020.sql', 'author': {'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/user?accountId=712020%3A7d15570a-3512-4d4d-8c3d-85e6359b582c', 'accountId': '712020:7d15570a-3512-4d4d-8c3d-85e6359b582c', 'emailAddress': 'clerambeau370@gmail.com', 'avatarUrls': {'48x48': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/48', '24x24': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/24', '16x16': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/16', '32x32': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/32'}, 'displayName': 'clerambeau', 'active': True, 'timeZone': 'US/Eastern', 'accountType': 'atlassian'}, 'created': '2026-05-04T18:48:05.045-0400', 'size': 59, 'mimeType': 'text/plain', 'content': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10839', 'thumbnail': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/thumbnail/10839'})

TASK [Display downloaded SQL scripts | dcr_jira 2026-05-05T14:51:25Z] ***********************************************************************************************************************************
ok: [localhost] => (item={'msg': 'OK (59 bytes)', 'status_code': 200, 'changed': True, 'checksum_dest': None, 'checksum_src': '1d6f17974f8fac35730491dedd15469be2f9dd41', 'dest': '/mnt/dba/automation/dcr/runtime/DCR_020.sql', 'elapsed': 0, 'url': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10839', 'src': '/home/misoracle/.ansible/tmp/ansible-tmp-1777992686.9735906-2926797-247724442560080/tmp7jl0sry0', 'md5sum': '268eb495f2fda3b4247c21a3b59a1632', 'uid': 55561, 'gid': 55561, 'owner': 'misoracle', 'group': 'misoracle', 'mode': '0644', 'state': 'file', 'size': 59, 'invocation': {'module_args': {'url': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10839', 'dest': '/mnt/dba/automation/dcr/runtime/DCR_020.sql', 'url_username': 'clerambeau370@gmail.com', 'url_password': 'VALUE_SPECIFIED_IN_NO_LOG_PARAMETER', 'force_basic_auth': True, 'mode': '0644', 'force': False, 'http_agent': 'ansible-httpget', 'use_proxy': True, 'validate_certs': True, 'use_gssapi': False, 'backup': False, 'checksum': '', 'timeout': 10, 'unredirected_headers': [], 'decompress': True, 'use_netrc': True, 'unsafe_writes': False, 'client_cert': None, 'client_key': None, 'headers': None, 'tmp_dest': None, 'ciphers': None, 'owner': None, 'group': None, 'seuser': None, 'serole': None, 'selevel': None, 'setype': None, 'attributes': None}}, 'failed': False, 'item': {'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/10839', 'id': '10839', 'filename': 'DCR_020.sql', 'author': {'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/user?accountId=712020%3A7d15570a-3512-4d4d-8c3d-85e6359b582c', 'accountId': '712020:7d15570a-3512-4d4d-8c3d-85e6359b582c', 'emailAddress': 'clerambeau370@gmail.com', 'avatarUrls': {'48x48': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/48', '24x24': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/24', '16x16': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/16', '32x32': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/32'}, 'displayName': 'clerambeau', 'active': True, 'timeZone': 'US/Eastern', 'accountType': 'atlassian'}, 'created': '2026-05-04T18:48:05.045-0400', 'size': 59, 'mimeType': 'text/plain', 'content': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10839', 'thumbnail': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/thumbnail/10839'}, 'ansible_loop_var': 'item'}) => {}

MSG:

Downloaded: /mnt/dba/automation/dcr/runtime/DCR_020.sql

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

[misoracle@ehsmg-mis-dba1 ansible]$ 

However, as you can see in the playbook above, the issue ID is hardcoded:

   issue: KAN-83

the problem is that there will be MANY different issues with other IDs which we do not know in advance. So what I need is to change the playbook above to connect to JIRA, query it for all issues under the project DDI.

Here is a view of such dashboard. As you can see there are three issues instead of one now: KAN-63, KAN-82, KAN-83.

I have gone as far as being able to get the issue IDs debugged and specific directories created for each issue in another playbook.

---
- name: Get all task metadata for the DCR project 
  hosts: localhost
  connection: local
  gather_facts: true
  vars_files:
    - vars/main.yml

  tasks:

    - name: Set fact for Ansible date_time | dcr_jira {{ ansible_date_time.iso8601 }}
      delegate_to: localhost
      run_once: true
      set_fact: 
        currentdate: "{{ ansible_date_time.date }}"
        tags: linux
          
    - name: Display Ansible date fact | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.debug:   
        var: currentdate
      run_once: true
      tags: linux   

    - name: Set Ansible current time fact | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.set_fact:
        current_time: "{{ now(fmt='%Y-%m-%d_%H-%M-%S') }}"
      run_once: true
      tags: linux

    - name: Display the formatted time | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.debug:
        var: current_time

###############DOWNLOAD SECTION############################
    - name: Search for all issues in project {{ project_key }}
      community.general.jira:
        uri: "{{ jira_url }}"
        username: "{{ jira_user }}"
        password: "{{ jira_api_token }}"
        # Use cloud=true if using Jira Cloud
        cloud: true
        operation: search
        jql: "project = {{ project }}"
        # Set maxresults to high enough number to catch all tasks
        maxresults: 100
      register: pr01_issues

    - name: Display details of each JIRA task
      ansible.builtin.debug:
        msg: "Key: {{ item.key }}, Summary: {{ item.fields.summary }}, Status: {{ item.fields.status.name }}"
      loop: "{{ pr01_issues.meta.issues }}"
      # Only print essential information
      loop_control:
        label: "{{ item.key }}"

###########################################################

    - name: Create a directory with specific permissions
      ansible.builtin.file:
        path: "{{ scratchpad_dcr_runtime }}/{{ item.key }}"
        state: directory
        mode: '0755'
      loop: "{{ pr01_issues.meta.issues }}"
      loop_control:
        label: "{{ item.key }}"

Output:

[misoracle@ehsmg-mis-dba1 ansible]$ ap dcr_jira01.yml
[WARNING]: Found both group and host with same name: localhost
[WARNING]: Collection community.general does not support Ansible version 2.16.3

PLAY [Get all task metadata for the DCR project] ***********************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Set fact for Ansible date_time | dcr_jira 2026-05-05T14:43:02Z] **************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Display Ansible date fact | dcr_jira 2026-05-05T14:43:02Z] *******************************************************************************************************************************************************************************************
ok: [localhost] => {
    "currentdate": "2026-05-05"
}

TASK [Set Ansible current time fact | dcr_jira 2026-05-05T14:43:02Z] ***************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Display the formatted time | dcr_jira 2026-05-05T14:43:02Z] ******************************************************************************************************************************************************************************************
ok: [localhost] => {
    "current_time": "2026-05-05_10-43-02"
}

TASK [Search for all issues in project {{ project_key }}] **************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Display details of each JIRA task] *******************************************************************************************************************************************************************************************************************
ok: [localhost] => (item=KAN-83) => {}

MSG:

Key: KAN-83, Summary: 26_ardddddf2345345, Status: In Progress
ok: [localhost] => (item=KAN-82) => {}

MSG:

Key: KAN-82, Summary: 26_artfgsdfsf2345345, Status: In Progress
ok: [localhost] => (item=KAN-63) => {}

MSG:

Key: KAN-63, Summary: Refresh MO2 DDI, Status: In Progress

TASK [Create a directory with specific permissions] ********************************************************************************************************************************************************************************************************
changed: [localhost] => (item=KAN-83)
changed: [localhost] => (item=KAN-82)
changed: [localhost] => (item=KAN-63)

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

[misoracle@ehsmg-mis-dba1 ansible]$ 

However, when it is time to actually DOWNLOAD all attachments belonging to each issue (like KAN-82 and others) into the newly created directories, I am at a loss. Whatever I try doesnt work.

    - name: Download DCR SQL scripts to the server | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.get_url:
        url: "{{ item.content }}"
        dest: "{{ scratchpad_dcr_runtime }}/{{ item.filename }}"
        url_username: "{{ jira_user }}"
        url_password: "{{ jira_api_token }}"
        force_basic_auth: yes
        mode: '0644'
      loop: "{{ issue_data.results }}"
      loop_control:
        label: "{{ item.filename }}"
#      when: item.filename.endswith('.sql')
      register: download_results
TASK [Download DCR SQL scripts to the server | dcr_jira 2026-05-05T14:46:29Z] ******************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {}

MSG:

The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'content'. 'dict object' has no attribute 'content'

The error appears to be in '/etc/ansible/dcr_jira04.yml': line 68, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


    - name: Download DCR SQL scripts to the server | dcr_jira {{ ansible_date_time.iso8601 }}
      ^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:

    with_items:
      - {{ foo }}

Should be written as:

    with_items:
      - "{{ foo }}"


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

Please help. This is something simple I am missing about the looping and the variable to pass to the ansible.builtin.get_url

Thank you.
Nestor Kandinsky-Clerambeau.

In your (working) Display details of each JIRA task and Create a directory with specific permissions tasks, you are looping over

"{{ pr01_issues.meta.issues }}"

However, in your failing Download DCR SQL scripts to the server task, you are looping over

"{{ issue_data.results }}"

Yes, those two statements that generated the “register” for both of them were created by Google AI. I combined them in the posted playbook , tried to make them both work.

I changed the playbook. Now it downloads ALL scripts, but only places them in one created folder. But each script has to go into the folder named after the JIRA issue the scripts were attached to (one issue may have more than one SQL attachment) , like KAN-82.

That is because of {{ issue_data.results[0].meta.key }}

---
- name: Get all task metadata for the DCR project 
  hosts: localhost
  connection: local
  gather_facts: true
  vars_files:
    - vars/main.yml

  tasks:

    - name: Set fact for Ansible date_time | dcr_jira {{ ansible_date_time.iso8601 }}
      delegate_to: localhost
      run_once: true
      set_fact: 
        currentdate: "{{ ansible_date_time.date }}"
        tags: linux
          
    - name: Display Ansible date fact | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.debug:   
        var: currentdate
      run_once: true
      tags: linux   

    - name: Set Ansible current time fact | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.set_fact:
        current_time: "{{ now(fmt='%Y-%m-%d_%H-%M-%S') }}"
      run_once: true
      tags: linux

###############DOWNLOAD SECTION############################
    - name: Search for all issues in project {{ project_key }}
      community.general.jira:
        uri: "{{ jira_url }}"
        username: "{{ jira_user }}"
        password: "{{ jira_api_token }}"
        # Use cloud=true if using Jira Cloud
        cloud: true
        operation: search
        jql: "project = {{ project }}"
        maxresults: 100
      register: pr01_issues

    - name: Display details of each JIRA task
      ansible.builtin.debug:
        msg: "Key: {{ item.key }}, Summary: {{ item.fields.summary }}, Status: {{ item.fields.status.name }}"
      loop: "{{ pr01_issues.meta.issues }}"
      loop_control:
        label: "{{ item.key }}"

###########################################################

    - name: Create a directory with specific permissions
      ansible.builtin.file:
        path: "{{ scratchpad_dcr_runtime }}/{{ item.key }}"
        state: directory
        mode: '0755'
      loop: "{{ pr01_issues.meta.issues }}"
      loop_control:
        label: "{{ item.key }}"

    - name: Fetch Jira issue metadata | dcr_jira {{ ansible_date_time.iso8601 }}
      community.general.jira:
        uri: "{{ jira_url }}"
        username: "{{ jira_user }}"
        password: "{{ jira_api_token }}"
        operation: fetch
        issue: "{{ item.key }}"
      loop: "{{ pr01_issues.meta.issues }}"
      loop_control:
        label: "{{ item.key }}"
      register: issue_data

    - name: Download DCR SQL scripts to the server | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.get_url:
        url: "{{ item.content }}"  
        dest: "{{ scratchpad_dcr_runtime }}/{{ issue_data.results[0].meta.key }}/{{ item.filename }}"     
        url_username: "{{ jira_user }}"
        url_password: "{{ jira_api_token }}"
        force_basic_auth: yes
        mode: '0644'
      loop: "{{ issue_data.results | selectattr('meta.fields.attachment', 'defined') | map(attribute='meta.fields.attachment') | list | flatten }}"
#      when: issue_data.meta.fields.attachment is defined
      register: download_results

Output:

[misoracle@ehsmg-mis-dba1 ansible]$ ap dcr_jira06.yml 
[WARNING]: Found both group and host with same name: localhost
[WARNING]: Collection community.general does not support Ansible version 2.16.3

PLAY [Get all task metadata for the DCR project] **************************************************************************************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Set fact for Ansible date_time | dcr_jira 2026-05-05T19:40:42Z] *****************************************************************************************************************************************************************
ok: [localhost]

TASK [Display Ansible date fact | dcr_jira 2026-05-05T19:40:42Z] **********************************************************************************************************************************************************************
ok: [localhost] => {
    "currentdate": "2026-05-05"
}

TASK [Set Ansible current time fact | dcr_jira 2026-05-05T19:40:42Z] ******************************************************************************************************************************************************************
ok: [localhost]

TASK [Search for all issues in project {{ project_key }}] *****************************************************************************************************************************************************************************
ok: [localhost]

TASK [Display details of each JIRA task] **********************************************************************************************************************************************************************************************
ok: [localhost] => (item=KAN-83) => {}

MSG:

Key: KAN-83, Summary: 26_ardddddf2345345, Status: In Progress
ok: [localhost] => (item=KAN-82) => {}

MSG:

Key: KAN-82, Summary: 26_artfgsdfsf2345345, Status: In Progress
ok: [localhost] => (item=KAN-63) => {}

MSG:

Key: KAN-63, Summary: Refresh MO2 DDI, Status: In Progress

TASK [Create a directory with specific permissions] ***********************************************************************************************************************************************************************************
changed: [localhost] => (item=KAN-83)
changed: [localhost] => (item=KAN-82)
changed: [localhost] => (item=KAN-63)

TASK [Fetch Jira issue metadata | dcr_jira 2026-05-05T19:40:42Z] **********************************************************************************************************************************************************************
ok: [localhost] => (item=KAN-83)
ok: [localhost] => (item=KAN-82)
ok: [localhost] => (item=KAN-63)

TASK [Download DCR SQL scripts to the server | dcr_jira 2026-05-05T19:40:42Z] *********************************************************************************************************************************************************
changed: [localhost] => (item={'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/10839', 'id': '10839', 'filename': 'DCR_020.sql', 'author': {'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/user?accountId=712020%3A7d15570a-3512-4d4d-8c3d-85e6359b582c', 'accountId': '712020:7d15570a-3512-4d4d-8c3d-85e6359b582c', 'emailAddress': 'clerambeau370@gmail.com', 'avatarUrls': {'48x48': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/48', '24x24': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/24', '16x16': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/16', '32x32': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/32'}, 'displayName': 'clerambeau', 'active': True, 'timeZone': 'US/Eastern', 'accountType': 'atlassian'}, 'created': '2026-05-04T18:48:05.045-0400', 'size': 59, 'mimeType': 'text/plain', 'content': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10839', 'thumbnail': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/thumbnail/10839'})
changed: [localhost] => (item={'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/10872', 'id': '10872', 'filename': 'DCR_001.sql', 'author': {'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/user?accountId=712020%3A7d15570a-3512-4d4d-8c3d-85e6359b582c', 'accountId': '712020:7d15570a-3512-4d4d-8c3d-85e6359b582c', 'emailAddress': 'clerambeau370@gmail.com', 'avatarUrls': {'48x48': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/48', '24x24': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/24', '16x16': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/16', '32x32': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/32'}, 'displayName': 'clerambeau', 'active': True, 'timeZone': 'US/Eastern', 'accountType': 'atlassian'}, 'created': '2026-05-05T14:24:34.700-0400', 'size': 60, 'mimeType': 'text/plain', 'content': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10872'})
changed: [localhost] => (item={'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/10874', 'id': '10874', 'filename': 'DCR_002.sql', 'author': {'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/user?accountId=712020%3A7d15570a-3512-4d4d-8c3d-85e6359b582c', 'accountId': '712020:7d15570a-3512-4d4d-8c3d-85e6359b582c', 'emailAddress': 'clerambeau370@gmail.com', 'avatarUrls': {'48x48': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/48', '24x24': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/24', '16x16': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/16', '32x32': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/32'}, 'displayName': 'clerambeau', 'active': True, 'timeZone': 'US/Eastern', 'accountType': 'atlassian'}, 'created': '2026-05-05T14:24:34.770-0400', 'size': 59, 'mimeType': 'text/plain', 'content': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10874'})
changed: [localhost] => (item={'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/10875', 'id': '10875', 'filename': 'DCR_003.sql', 'author': {'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/user?accountId=712020%3A7d15570a-3512-4d4d-8c3d-85e6359b582c', 'accountId': '712020:7d15570a-3512-4d4d-8c3d-85e6359b582c', 'emailAddress': 'clerambeau370@gmail.com', 'avatarUrls': {'48x48': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/48', '24x24': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/24', '16x16': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/16', '32x32': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/32'}, 'displayName': 'clerambeau', 'active': True, 'timeZone': 'US/Eastern', 'accountType': 'atlassian'}, 'created': '2026-05-05T14:24:34.814-0400', 'size': 59, 'mimeType': 'text/plain', 'content': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10875'})
changed: [localhost] => (item={'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/10876', 'id': '10876', 'filename': 'DCR_004.sql', 'author': {'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/user?accountId=712020%3A7d15570a-3512-4d4d-8c3d-85e6359b582c', 'accountId': '712020:7d15570a-3512-4d4d-8c3d-85e6359b582c', 'emailAddress': 'clerambeau370@gmail.com', 'avatarUrls': {'48x48': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/48', '24x24': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/24', '16x16': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/16', '32x32': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/32'}, 'displayName': 'clerambeau', 'active': True, 'timeZone': 'US/Eastern', 'accountType': 'atlassian'}, 'created': '2026-05-05T14:24:34.712-0400', 'size': 59, 'mimeType': 'text/plain', 'content': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10876'})
changed: [localhost] => (item={'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/10873', 'id': '10873', 'filename': 'DCR_005.sql', 'author': {'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/user?accountId=712020%3A7d15570a-3512-4d4d-8c3d-85e6359b582c', 'accountId': '712020:7d15570a-3512-4d4d-8c3d-85e6359b582c', 'emailAddress': 'clerambeau370@gmail.com', 'avatarUrls': {'48x48': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/48', '24x24': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/24', '16x16': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/16', '32x32': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/32'}, 'displayName': 'clerambeau', 'active': True, 'timeZone': 'US/Eastern', 'accountType': 'atlassian'}, 'created': '2026-05-05T14:24:34.760-0400', 'size': 58, 'mimeType': 'text/plain', 'content': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10873'})
changed: [localhost] => (item={'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/10837', 'id': '10837', 'filename': 'DCR_016.sql', 'author': {'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/user?accountId=712020%3A7d15570a-3512-4d4d-8c3d-85e6359b582c', 'accountId': '712020:7d15570a-3512-4d4d-8c3d-85e6359b582c', 'emailAddress': 'clerambeau370@gmail.com', 'avatarUrls': {'48x48': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/48', '24x24': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/24', '16x16': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/16', '32x32': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/32'}, 'displayName': 'clerambeau', 'active': True, 'timeZone': 'US/Eastern', 'accountType': 'atlassian'}, 'created': '2026-05-04T18:47:43.078-0400', 'size': 59, 'mimeType': 'text/plain', 'content': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10837', 'thumbnail': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/thumbnail/10837'})

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

So, the result is this:

So, all 7 scripts went into the KAN-83 folder. The actual attachments are spread like this:

KAN-82: DCR_001.sql DCR_002.sql DCR_003.sql DCR_004.sql DCR_005.sql DCR_016.sql
KAN-83: DCR_020.sql
KAN-63: empty

So, how do I send all attachments to their own folders?

Thanks @utoddl

I may be overcomlicating the matter. A better way perhaps is NOT to download them into separate folders for script running, but instead download each KAN-XXX , process it, then the next one, process that one and so on, by importing a separate playbook or a task book (import tasks).
But I dont know how to do that.

It’s not hard to do what you want — you’ll end up using ansible.builtin.subelements to get the loops to match up (like we did before with the ServiceNow change requests). What is hard (for me anyway) is to figure out exactly what your data looks like. I’ve nearly got it, but I need to step away for a couple of hours. I’ll touch back later.

Thank you. Posting the data. The key components are:

The issue identifier:

  "key": "KAN-83"

and the attachment(s) to the issue key KAN-83 above:

 "content": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10839",
                        "created": "2026-05-04T18:48:05.045-0400",
                        "filename": "DCR_020.sql",
                        "id": "10839",

The way to download it is to use get_url to get the “content” URL from above, like https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10839.

        - name: Download DCR SQL scripts to the server | dcr_jira {{ ansible_date_time.iso8601 }}
          ansible.builtin.get_url:
            url: "{{ item.content }}"
            dest: "{{ scratchpad_dcr_runtime }}/{{ item.filename }}"
            url_username: "{{ jira_user }}"
            url_password: "{{ jira_api_token }}"

I am posting a debug of a JIRA issue KAN-83 only (remember, there will be multiple issues!). It has only one attachment DCR_020.sql.

---
- name: Get all task metadata for the DCR project 
  hosts: localhost
  connection: local
  gather_facts: true
  vars_files:
    - vars/main.yml

  tasks:

    - name: Set fact for Ansible date_time | dcr_jira {{ ansible_date_time.iso8601 }}
      delegate_to: localhost
      run_once: true
      set_fact: 
        currentdate: "{{ ansible_date_time.date }}"
        tags: linux
          
    - name: Display Ansible date fact | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.debug:   
        var: currentdate
      run_once: true
      tags: linux   

    - name: Set Ansible current time fact | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.set_fact:
        current_time: "{{ now(fmt='%Y-%m-%d_%H-%M-%S') }}"
      run_once: true
      tags: linux

###############DOWNLOAD SECTION############################

    - name: Fetch Jira issue metadata | dcr_jira {{ ansible_date_time.iso8601 }}
      community.general.jira:
        uri: "{{ jira_url }}"
        username: "{{ jira_user }}"
        password: "{{ jira_api_token }}"
        operation: fetch
#        issue: "{{ issue_key }}"
        issue: KAN-83
      register: issue_data
      delegate_to: localhost

    - name: Display DDI Refresh task unique Key
      ansible.builtin.debug:   
        var: issue_data

####################CODITIONALS DEBUG###################################

    - name: Set fact for task unique key | dcr_jira {{ ansible_date_time.iso8601 }}
      delegate_to: localhost
      run_once: true
      set_fact: 
        task_unique_key: "{{ issue_data.meta.key }}"
      tags: linux

    - name: Display DCR task unique Key | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.debug:   
        var: "{{ task_unique_key }}"

    - name: Display DCR Status | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.debug:   
        var: issue_data.meta.fields.status.name

    - name: Display DCR Assignee | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.debug:   
        var: issue_data.meta.fields.assignee.displayName

    - name: Display DCR Due Date | dcr_jira {{ ansible_date_time.iso8601 }}
      ansible.builtin.debug:   
        var: issue_data.meta.fields.duedate

    - name: Announce Task launch if DCR Status is in Implementation, Assigned to Automation and Due Date is today | dcr_jira {{ ansible_date_time.iso8601 }}
      debug:
        msg: "DCR Status has changed to 'In Progress', the Task is now assigned to 'Automation API' and Due Date is today. Proceeding with DCR tasks automation at {{ ansible_date_time.iso8601 }}."
      when: >
        "In Progress" in issue_data.meta.fields.status.name and 
        "Automation API" in issue_data.meta.fields.assignee.displayName and 
        "{{ now(fmt='%Y-%m-%d') }}" in issue_data.meta.fields.duedate

####################END OF CONDITIONALS DEBUG###########################

    - name: Run the DCR refresh conditional block to only execute when the conditions are met | dcr_jira {{ ansible_date_time.iso8601 }}
      block:

#        - name: Truncate the Ansible log
#          ansible.builtin.shell:
#            cmd: "truncate --s 0 /var/log/ansible/hosts/localhost"   

        - name: Download DCR SQL scripts to the server | dcr_jira {{ ansible_date_time.iso8601 }}
          ansible.builtin.get_url:
            url: "{{ item.content }}"
            dest: "{{ scratchpad_dcr_runtime }}/{{ item.filename }}"
            url_username: "{{ jira_user }}"
            url_password: "{{ jira_api_token }}"
            force_basic_auth: yes
            mode: '0644'
          loop: "{{ issue_data.meta.fields.attachment }}"
          when: issue_data.meta.fields.attachment is defined
          register: download_results

        - name: Display downloaded SQL scripts | dcr_jira {{ ansible_date_time.iso8601 }}
          ansible.builtin.debug:
            msg: "Downloaded: {{ item.dest }}"
          loop: "{{ download_results.results }}"
          when: item.changed
[misoracle@ehsmg-mis-dba1 ansible]$ ap dcr.yml 
[WARNING]: Found both group and host with same name: localhost
[WARNING]: Collection community.general does not support Ansible version 2.16.3

PLAY [Get all task metadata for the DCR project] **************************************************************************************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Set fact for Ansible date_time | dcr_jira 2026-05-05T21:03:30Z] *****************************************************************************************************************************************************************
ok: [localhost]

TASK [Display Ansible date fact | dcr_jira 2026-05-05T21:03:30Z] **********************************************************************************************************************************************************************
ok: [localhost] => {
    "currentdate": "2026-05-05"
}

TASK [Set Ansible current time fact | dcr_jira 2026-05-05T21:03:30Z] ******************************************************************************************************************************************************************
ok: [localhost]

TASK [Fetch Jira issue metadata | dcr_jira 2026-05-05T21:03:30Z] **********************************************************************************************************************************************************************
ok: [localhost]

TASK [Display DDI Refresh task unique Key] ********************************************************************************************************************************************************************************************
ok: [localhost] => {
    "issue_data": {
        "changed": false,
        "failed": false,
        "meta": {
            "expand": "renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations",
            "fields": {
                "aggregateprogress": {
                    "progress": 0,
                    "total": 0
                },
                "aggregatetimeestimate": null,
                "aggregatetimeoriginalestimate": null,
                "aggregatetimespent": null,
                "assignee": {
                    "accountId": "712020:bd36fd4b-0ab9-4a12-a623-7cfbc1e087cb",
                    "accountType": "atlassian",
                    "active": true,
                    "avatarUrls": {
                        "16x16": "https://secure.gravatar.com/avatar/5ff7bab43fcce90b5411161bc83756c1?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FAA-6.png",
                        "24x24": "https://secure.gravatar.com/avatar/5ff7bab43fcce90b5411161bc83756c1?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FAA-6.png",
                        "32x32": "https://secure.gravatar.com/avatar/5ff7bab43fcce90b5411161bc83756c1?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FAA-6.png",
                        "48x48": "https://secure.gravatar.com/avatar/5ff7bab43fcce90b5411161bc83756c1?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FAA-6.png"
                    },
                    "displayName": "Automation API",
                    "self": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/user?accountId=712020%3Abd36fd4b-0ab9-4a12-a623-7cfbc1e087cb",
                    "timeZone": "America/New_York"
                },
                "attachment": [
                    {
                        "author": {
                            "accountId": "712020:7d15570a-3512-4d4d-8c3d-85e6359b582c",
                            "accountType": "atlassian",
                            "active": true,
                            "avatarUrls": {
                                "16x16": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/16",
                                "24x24": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/24",
                                "32x32": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/32",
                                "48x48": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/48"
                            },
                            "displayName": "clerambeau",
                            "emailAddress": "clerambeau370@gmail.com",
                            "self": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/user?accountId=712020%3A7d15570a-3512-4d4d-8c3d-85e6359b582c",
                            "timeZone": "US/Eastern"
                        },
                        "content": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10839",
                        "created": "2026-05-04T18:48:05.045-0400",
                        "filename": "DCR_020.sql",
                        "id": "10839",
                        "mimeType": "text/plain",
                        "self": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/10839",
                        "size": 59,
                        "thumbnail": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/thumbnail/10839"
                    }
                ],
                "comment": {
                    "comments": [],
                    "maxResults": 0,
                    "self": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/issue/10456/comment",
                    "startAt": 0,
                    "total": 0
                },
                "components": [],
                "created": "2026-05-04T18:48:06.143-0400",
                "creator": {
                    "accountId": "712020:7d15570a-3512-4d4d-8c3d-85e6359b582c",
                    "accountType": "atlassian",
                    "active": true,
                    "avatarUrls": {
                        "16x16": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/16",
                        "24x24": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/24",
                        "32x32": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/32",
                        "48x48": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/48"
                    },
                    "displayName": "clerambeau",
                    "emailAddress": "clerambeau370@gmail.com",
                    "self": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/user?accountId=712020%3A7d15570a-3512-4d4d-8c3d-85e6359b582c",
                    "timeZone": "US/Eastern"
                },
                "customfield_10000": "{}",
                "customfield_10001": null,
                "customfield_10015": null,
                "customfield_10019": "0|i0003j:",
                "customfield_10021": null,
                "customfield_10038": null,
                "customfield_10071": null,
                "customfield_10110": null,
                "customfield_10111": [
                    {
                        "accountId": "712020:bd36fd4b-0ab9-4a12-a623-7cfbc1e087cb",
                        "accountType": "atlassian",
                        "active": true,
                        "avatarUrls": {
                            "16x16": "https://secure.gravatar.com/avatar/5ff7bab43fcce90b5411161bc83756c1?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FAA-6.png",
                            "24x24": "https://secure.gravatar.com/avatar/5ff7bab43fcce90b5411161bc83756c1?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FAA-6.png",
                            "32x32": "https://secure.gravatar.com/avatar/5ff7bab43fcce90b5411161bc83756c1?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FAA-6.png",
                            "48x48": "https://secure.gravatar.com/avatar/5ff7bab43fcce90b5411161bc83756c1?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FAA-6.png"
                        },
                        "displayName": "Automation API",
                        "self": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/user?accountId=712020%3Abd36fd4b-0ab9-4a12-a623-7cfbc1e087cb",
                        "timeZone": "America/New_York"
                    }
                ],
                "customfield_10112": null,
                "customfield_10113": null,
                "description": null,
                "duedate": "2026-05-04",
                "environment": null,
                "fixVersions": [],
                "issuelinks": [],
                "issuerestriction": {
                    "issuerestrictions": {},
                    "shouldDisplay": true
                },
                "issuetype": {
                    "avatarId": 10318,
                    "description": "Tasks track small, distinct pieces of work.",
                    "entityId": "30253b1e-808f-4560-9c74-dc750c1dd428",
                    "hierarchyLevel": 0,
                    "iconUrl": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10318?size=medium",
                    "id": "10003",
                    "name": "Task",
                    "self": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/issuetype/10003",
                    "subtask": false
                },
                "labels": [
                    "form",
                    "form-100"
                ],
                "lastViewed": "2026-05-05T17:02:39.001-0400",
                "priority": {
                    "iconUrl": "https://clerambeau370-1776214257398.atlassian.net/images/icons/priorities/medium_new.svg",
                    "id": "3",
                    "name": "Medium",
                    "self": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/priority/3"
                },
                "progress": {
                    "progress": 0,
                    "total": 0
                },
                "project": {
                    "avatarUrls": {
                        "16x16": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/universal_avatar/view/type/project/avatar/10754?size=xsmall",
                        "24x24": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/universal_avatar/view/type/project/avatar/10754?size=small",
                        "32x32": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/universal_avatar/view/type/project/avatar/10754?size=medium",
                        "48x48": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/universal_avatar/view/type/project/avatar/10754"
                    },
                    "id": "10000",
                    "key": "KAN",
                    "name": "DDI",
                    "projectTypeKey": "software",
                    "self": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/project/10000",
                    "simplified": true
                },
                "reporter": {
                    "accountId": "712020:7d15570a-3512-4d4d-8c3d-85e6359b582c",
                    "accountType": "atlassian",
                    "active": true,
                    "avatarUrls": {
                        "16x16": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/16",
                        "24x24": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/24",
                        "32x32": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/32",
                        "48x48": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/48"
                    },
                    "displayName": "clerambeau",
                    "emailAddress": "clerambeau370@gmail.com",
                    "self": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/user?accountId=712020%3A7d15570a-3512-4d4d-8c3d-85e6359b582c",
                    "timeZone": "US/Eastern"
                },
                "resolution": null,
                "resolutiondate": null,
                "security": null,
                "status": {
                    "description": "This work item is being actively worked on at the moment by the assignee.",
                    "iconUrl": "https://clerambeau370-1776214257398.atlassian.net/images/icons/statuses/generic.png",
                    "id": "10001",
                    "name": "In Progress",
                    "self": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/status/10001",
                    "statusCategory": {
                        "colorName": "yellow",
                        "id": 4,
                        "key": "indeterminate",
                        "name": "In Progress",
                        "self": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/statuscategory/4"
                    }
                },
                "statusCategory": {
                    "colorName": "yellow",
                    "id": 4,
                    "key": "indeterminate",
                    "name": "In Progress",
                    "self": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/statuscategory/4"
                },
                "statuscategorychangedate": "2026-05-04T18:48:16.276-0400",
                "subtasks": [],
                "summary": "26_ardddddf2345345",
                "timeestimate": null,
                "timeoriginalestimate": null,
                "timespent": null,
                "timetracking": {},
                "updated": "2026-05-05T10:39:11.537-0400",
                "versions": [],
                "votes": {
                    "hasVoted": false,
                    "self": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/issue/KAN-83/votes",
                    "votes": 0
                },
                "watches": {
                    "isWatching": true,
                    "self": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/issue/KAN-83/watchers",
                    "watchCount": 1
                },
                "worklog": {
                    "maxResults": 20,
                    "startAt": 0,
                    "total": 0,
                    "worklogs": []
                },
                "workratio": -1
            },
            "id": "10456",
            "key": "KAN-83",
            "self": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2/issue/10456"
        },
        "restbase": "https://clerambeau370-1776214257398.atlassian.net/rest/api/2",
        "state": "fetch"
    }
}

TASK [Set fact for task unique key | dcr_jira 2026-05-05T21:03:30Z] *******************************************************************************************************************************************************************
ok: [localhost]

TASK [Display DCR task unique Key | dcr_jira 2026-05-05T21:03:30Z] ********************************************************************************************************************************************************************
ok: [localhost] => {
    "KAN-83": "{{KAN-83}}"
}

TASK [Display DCR Status | dcr_jira 2026-05-05T21:03:30Z] *****************************************************************************************************************************************************************************
ok: [localhost] => {
    "issue_data.meta.fields.status.name": "In Progress"
}

TASK [Display DCR Assignee | dcr_jira 2026-05-05T21:03:30Z] ***************************************************************************************************************************************************************************
ok: [localhost] => {
    "issue_data.meta.fields.assignee.displayName": "Automation API"
}

TASK [Display DCR Due Date | dcr_jira 2026-05-05T21:03:30Z] ***************************************************************************************************************************************************************************
ok: [localhost] => {
    "issue_data.meta.fields.duedate": "2026-05-04"
}

TASK [Announce Task launch if DCR Status is in Implementation, Assigned to Automation and Due Date is today | dcr_jira 2026-05-05T21:03:30Z] ******************************************************************************************
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: "In Progress" in issue_data.meta.fields.status.name and  "Automation API" in
issue_data.meta.fields.assignee.displayName and  "{{ now(fmt='%Y-%m-%d') }}" in issue_data.meta.fields.duedate
skipping: [localhost]

TASK [Download DCR SQL scripts to the server | dcr_jira 2026-05-05T21:03:30Z] *********************************************************************************************************************************************************
ok: [localhost] => (item={'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/10839', 'id': '10839', 'filename': 'DCR_020.sql', 'author': {'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/user?accountId=712020%3A7d15570a-3512-4d4d-8c3d-85e6359b582c', 'accountId': '712020:7d15570a-3512-4d4d-8c3d-85e6359b582c', 'emailAddress': 'clerambeau370@gmail.com', 'avatarUrls': {'48x48': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/48', '24x24': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/24', '16x16': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/16', '32x32': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/32'}, 'displayName': 'clerambeau', 'active': True, 'timeZone': 'US/Eastern', 'accountType': 'atlassian'}, 'created': '2026-05-04T18:48:05.045-0400', 'size': 59, 'mimeType': 'text/plain', 'content': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10839', 'thumbnail': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/thumbnail/10839'})

TASK [Display downloaded SQL scripts | dcr_jira 2026-05-05T21:03:30Z] *****************************************************************************************************************************************************************
skipping: [localhost] => (item={'msg': 'OK (59 bytes)', 'status_code': 200, 'changed': False, 'checksum_dest': '1d6f17974f8fac35730491dedd15469be2f9dd41', 'checksum_src': '1d6f17974f8fac35730491dedd15469be2f9dd41', 'dest': '/mnt/dba/automation/dcr/runtime/DCR_020.sql', 'elapsed': 0, 'url': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10839', 'src': '/home/misoracle/.ansible/tmp/ansible-tmp-1778015011.763888-2983003-128381506860384/tmpdwzblwng', 'md5sum': '268eb495f2fda3b4247c21a3b59a1632', 'uid': 55561, 'gid': 55561, 'owner': 'misoracle', 'group': 'misoracle', 'mode': '0644', 'state': 'file', 'size': 59, 'invocation': {'module_args': {'url': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10839', 'dest': '/mnt/dba/automation/dcr/runtime/DCR_020.sql', 'url_username': 'clerambeau370@gmail.com', 'url_password': 'VALUE_SPECIFIED_IN_NO_LOG_PARAMETER', 'force_basic_auth': True, 'mode': '0644', 'force': False, 'http_agent': 'ansible-httpget', 'use_proxy': True, 'validate_certs': True, 'use_gssapi': False, 'backup': False, 'checksum': '', 'timeout': 10, 'unredirected_headers': [], 'decompress': True, 'use_netrc': True, 'unsafe_writes': False, 'client_cert': None, 'client_key': None, 'headers': None, 'tmp_dest': None, 'ciphers': None, 'owner': None, 'group': None, 'seuser': None, 'serole': None, 'selevel': None, 'setype': None, 'attributes': None}}, 'failed': False, 'item': {'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/10839', 'id': '10839', 'filename': 'DCR_020.sql', 'author': {'self': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/user?accountId=712020%3A7d15570a-3512-4d4d-8c3d-85e6359b582c', 'accountId': '712020:7d15570a-3512-4d4d-8c3d-85e6359b582c', 'emailAddress': 'clerambeau370@gmail.com', 'avatarUrls': {'48x48': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/48', '24x24': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/24', '16x16': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/16', '32x32': 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:7d15570a-3512-4d4d-8c3d-85e6359b582c/486224f3-f8a3-483f-b14c-acb285a53f79/32'}, 'displayName': 'clerambeau', 'active': True, 'timeZone': 'US/Eastern', 'accountType': 'atlassian'}, 'created': '2026-05-04T18:48:05.045-0400', 'size': 59, 'mimeType': 'text/plain', 'content': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/content/10839', 'thumbnail': 'https://clerambeau370-1776214257398.atlassian.net/rest/api/2/attachment/thumbnail/10839'}, 'ansible_loop_var': 'item'}) 
skipping: [localhost]

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

[misoracle@ehsmg-mis-dba1 ansible]$ 

Try something like this:

    - name: Issues × Attachments using ansible.builtin.subelements
      ansible.builtin.debug:
        msg:
          Issue_Key: "{{ item[0].meta.key }}"
          Attachment_filename: "{{ item[1].filename }}"
          Content_URL: "{{ item[1].content }}"
      loop: "{{ pr01_issues.meta.issues
                | ansible.builtin.subelements('meta.fields.attachment', skip_missing=true) }}"
      loop_control:
        label: "{{ item[0].meta.key, item[1].filename }}"

Given your issue to attachment is like this:

KAN-82: DCR_001.sql DCR_002.sql DCR_003.sql DCR_004.sql DCR_005.sql DCR_016.sql
KAN-83: DCR_020.sql
KAN-63: empty

the above |subelements() will produce a list of issue×attachment pairs to iterate over consisting of

- [KAN-82, DCR_001.sql]
- [KAN-82, DCR_002.sql]
- [KAN-82, DCR_003.sql]
- [KAN-82, DCR_004.sql]
- [KAN-82, DCR_005.sql]
- [KAN-82, DCR_016.sql]
- [KAN-83, DCR_020.sql]

Note there is no KAN-63 because of the skip_missing=true.

[Edit, in case it wasn’t clear — they aren’t literally those strings, but rather the whole issue dict with key “KAN-82” (for example) and the whole attachment dict with the indicated filenames.]

Unfortunately, It gets skipped. I turned the “-vvvv” to check why. Will report back. Thanks for taking the time to reply anyway, that is greatly appreciated

@utoddl I decided to bypass this issue with downloading attachments from several JIRA tickets. Instead, it is just easier to reuse one JIRA with the same key. I put in some functionality that allows

  1. Renaming the ticket (but just the Summary gets renamed, they key remains unchanged);
  2. Automatically deletes all passwords and uploads a zipped file of the run logs for the JIRA task;

Essentially, that is cleaner as there is just one task per environment (there are 12 such envs) and all records are preserved.

Thank you for your help, sir.

Nestor.