# Access to the job id variable from running tasks?

**URL:** <https://forum.ansible.com/t/access-to-the-job-id-variable-from-running-tasks/13488>\
**Category:** Ansible Project\
**Created:** [September 16, 2013, 9:19pm UTC](https://forum.ansible.com/t/access-to-the-job-id-variable-from-running-tasks/13488 "2013-09-16T21:19:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Mitchell](https://avatars.discourse-cdn.com/v4/letter/r/4bbf92/32.png) [@Ryan\_Mitchell](https://forum.ansible.com/u/Ryan_Mitchell)\
**Post date:** [September 16, 2013, 9:19pm UTC](https://forum.ansible.com/t/access-to-the-job-id-variable-from-running-tasks/13488/1 "2013-09-16T21:19:21Z")

</div>

I’m working on a play where I use the template module to put a shell script on the remote filesystem and then run that script. However, it’s inherently single-threaded because a) it’s a delegated task to a single database server for all hosts and b) the name of the file is the same - so it creates a race condition.

One option is for me to generate a random UUID and append the filename with that to force unique filenames (and thus allow me to run each script in parallel on the single remote endpoint), but I figured the job id might be a good option as well. However, as I was reading it looks like the job id is the same for all endpoints running the same task in a play - which means that’s not a good option. Additionally, I don’t see any documentation about how to get the job id back as part of the action (i.e. as a variable).

Any recommendations here for something more “clever” than just creating text to append to the filename using something like originating hostname + epoch or something like that?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 16, 2013, 9:23pm UTC](https://forum.ansible.com/t/access-to-the-job-id-variable-from-running-tasks/13488/2 "2013-09-16T21:23:36Z")

</div>

delegate\_to in Ansible does not make things run in a single process, it’s still parallel.

you can use the serial: 1 keyword, however, to make things work on just one thing at a time if you need things to happen that way.

If you want a unique filename for each individual server you could perhaps use “{{inventory\_hostname}}” in the filename, which is the name of the host you are looping over.

---

<div class="post-metadata">

**Author:** ![Ryan\_Mitchell](https://avatars.discourse-cdn.com/v4/letter/r/4bbf92/32.png) [@Ryan\_Mitchell](https://forum.ansible.com/u/Ryan_Mitchell)\
**Post date:** [September 16, 2013, 10:06pm UTC](https://forum.ansible.com/t/access-to-the-job-id-variable-from-running-tasks/13488/3 "2013-09-16T22:06:00Z")

</div>

Yep, that’s what I’m doing right now for the database side, the serial: 1 works really well. The inventory\_hostname was my next stop but I figured it’d still be safer to find something with more granularity, like the job id. But this will work too. Thanks.
