# problem passing var between tasks.

**URL:** <https://forum.ansible.com/t/problem-passing-var-between-tasks/32997>\
**Category:** Ansible Project\
**Created:** [May 21, 2020, 3:38pm UTC](https://forum.ansible.com/t/problem-passing-var-between-tasks/32997 "2020-05-21T15:38:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeremy\_Hobbs](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@Jeremy\_Hobbs](https://forum.ansible.com/u/Jeremy_Hobbs)\
**Post date:** [May 21, 2020, 3:38pm UTC](https://forum.ansible.com/t/problem-passing-var-between-tasks/32997/1 "2020-05-21T15:38:38Z")

</div>

I have a problem passing a variable between playbooks that are chained together. Any thoughts?

Playbook - audit\_hardware\_inventory.yml

---

<div class="post-metadata">

**Author:** ![David\_Foley](https://avatars.discourse-cdn.com/v4/letter/d/9e8a1a/32.png) [@David\_Foley](https://forum.ansible.com/u/David_Foley)\
**Post date:** [May 21, 2020, 3:49pm UTC](https://forum.ansible.com/t/problem-passing-var-between-tasks/32997/2 "2020-05-21T15:49:04Z")

</div>

Why two Playbook ?

But either way, Copy the Reg to a Local Json File

Then in your Second Playbook Just read in the JSON File

name: Read Json File  
shell: cat Info.json  
register: json\_file

(json\_file.stdout | from\_json).VALUE

---

<div class="post-metadata">

**Author:** ![Jeremy\_Hobbs](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@Jeremy\_Hobbs](https://forum.ansible.com/u/Jeremy_Hobbs)\
**Post date:** [May 21, 2020, 3:55pm UTC](https://forum.ansible.com/t/problem-passing-var-between-tasks/32997/3 "2020-05-21T15:55:59Z")

</div>

I simplified the playbook for the post. But, this specific call is used by many different playbooks. So instead of having to update each playbook if it changes, I want to abstract it out. Writing to a file seems a pretty crappy workaround. Is there not a way to pass variables between the playbooks directly?

---

<div class="post-metadata">

**Author:** ![David\_Foley](https://avatars.discourse-cdn.com/v4/letter/d/9e8a1a/32.png) [@David\_Foley](https://forum.ansible.com/u/David_Foley)\
**Post date:** [May 21, 2020, 4:05pm UTC](https://forum.ansible.com/t/problem-passing-var-between-tasks/32997/4 "2020-05-21T16:05:18Z")

</div>

Another way I know is to send the reg to the stdout and cat that stdout into the other playbook.  
similar to outputting to the File, but if the API Value is big you may be better off with the Text File.

```auto
     register: test
   - debug: msg="{{test.stdout}}"

```

```auto
  tasks:
   - shell: cat "{{test.stdout}}"

```

---

<div class="post-metadata">

**Author:** ![Suneel\_Gali](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@Suneel\_Gali](https://forum.ansible.com/u/Suneel_Gali)\
**Post date:** [May 21, 2020, 4:11pm UTC](https://forum.ansible.com/t/problem-passing-var-between-tasks/32997/5 "2020-05-21T16:11:02Z")

</div>

can you try to pass the variable to include\_tasks?

**Reference** : [https://docs.ansible.com/ansible/devel/porting\_guides/porting\_guide\_2.7.html#include-tasks-import-tasks-inline-variables](https://docs.ansible.com/ansible/devel/porting_guides/porting_guide_2.7.html#include-tasks-import-tasks-inline-variables)

-Suneel

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 21, 2020, 4:11pm UTC](https://forum.ansible.com/t/problem-passing-var-between-tasks/32997/6 "2020-05-21T16:11:45Z")

</div>

Not tried yet, but this describes a dummy host:  
[https://stackoverflow.com/a/47811099/12731515](https://stackoverflow.com/a/47811099/12731515)

---

<div class="post-metadata">

**Author:** ![Jeremy\_Hobbs](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@Jeremy\_Hobbs](https://forum.ansible.com/u/Jeremy_Hobbs)\
**Post date:** [May 21, 2020, 6:14pm UTC](https://forum.ansible.com/t/problem-passing-var-between-tasks/32997/7 "2020-05-21T18:14:47Z")

</div>

Suneel, I attempted your solution, but it didn’t work with the way I was setting up the workflow. Dick, I tried the Dummy host and it worked perfectly. Thank you for your responses.

Jeremy
