# Use python output from file within ansible

**URL:** <https://forum.ansible.com/t/use-python-output-from-file-within-ansible/9741>\
**Category:** Get Help\
**Created:** [October 7, 2024, 10:53am UTC](https://forum.ansible.com/t/use-python-output-from-file-within-ansible/9741 "2024-10-07T10:53:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![M-K](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@M-K](https://forum.ansible.com/u/M-K)\
**Post date:** [October 7, 2024, 10:53am UTC](https://forum.ansible.com/t/use-python-output-from-file-within-ansible/9741/1 "2024-10-07T10:53:15Z")

</div>

Hello,

If I wanted to use the output from some script - chronic.py i.e  
result\_dict = {‘Incident\_number’: , ‘Event\_Name’: , ‘Hostname’: , ‘\_time’: };

## I can add in main.yml like this -

- name: execute info. fetch script  
script: chronic.py  
register: result\_dict

- debug:  
msg: “{{ result\_dict }}”

but how do I get the variables out from result\_that for further processing next in a different file within my playbook?

Thanks

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [October 8, 2024, 9:13pm UTC](https://forum.ansible.com/t/use-python-output-from-file-within-ansible/9741/2 "2024-10-08T21:13:01Z")

</div>

I added some fake values to your result\_dict so there would be something for the demo. Here’s a playbook with data like you describe.

```yaml
---
- name: Use python output from file within ansible
  hosts: localhost
  gather_facts: false
  vars:
    result_dict: {'Incident_number': [1,2,3],
                  'Event_Name': [a,b,c] ,
                  'Hostname': [h1,h2,h3],
                  '_time': [t1,t2,t3] }
  tasks:
    - name: loop over result_dict
      ansible.builtin.debug:
        msg: |
          Incident_number: {{ result_dict["Incident_number"][item] }}
          Event_Name: {{ result_dict["Event_Name"][item] }}
          Hostname: {{ result_dict["Hostname"][item] }}
          _time: {{ result_dict["_time"][item] }}
      loop: '{{ range(0, result_dict["Incident_number"] | length) }}'

```

And here is the relevant part of its output.

```plaintext
TASK [loop over result_dict] ***
ok: [localhost] => (item=0) => 
  msg: |-
    Incident_number: 1
    Event_Name: a
    Hostname: h1
    _time: t1
ok: [localhost] => (item=1) => 
  msg: |-
    Incident_number: 2
    Event_Name: b
    Hostname: h2
    _time: t2
ok: [localhost] => (item=2) => 
  msg: |-
    Incident_number: 3
    Event_Name: c
    Hostname: h3
    _time: t3

```
