# setting PATH in user crontab

**URL:** <https://forum.ansible.com/t/setting-path-in-user-crontab/15539>\
**Category:** Ansible Project\
**Created:** [June 24, 2014, 9:40pm UTC](https://forum.ansible.com/t/setting-path-in-user-crontab/15539 "2014-06-24T21:40:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christine\_Spang](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@Christine\_Spang](https://forum.ansible.com/u/Christine_Spang)\
**Post date:** [June 24, 2014, 9:40pm UTC](https://forum.ansible.com/t/setting-path-in-user-crontab/15539/1 "2014-06-24T21:40:50Z")

</div>

I’m using Ansible 1.6.3 to manage a user-specific crontab. This job runs a command which, as a part of the script, calls another script located in /usr/local/bin, which is not in cron’s default PATH on Debian systems.

#Ansible: do something  
0 9 \* \* \* /home/admin/bin/do-something \>~/logs/do-something.log 2\>&1

The script fails because it can’t find the command called within `do-something` in /usr/local/bin. The right way to fix this is to set PATH in the crontab, but I can’t see a way to do that with ansible’s cron module.

What’s the right way to solve this with Ansible?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [June 26, 2014, 1:24pm UTC](https://forum.ansible.com/t/setting-path-in-user-crontab/15539/2 "2014-06-26T13:24:30Z")

</div>

I don’t see why you think it would be looking in /usr/local/bin as you have hard coded the path above.

---

<div class="post-metadata">

**Author:** ![Scott\_Sturdivant](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@Scott\_Sturdivant](https://forum.ansible.com/u/Scott_Sturdivant)\
**Post date:** [June 26, 2014, 4:45pm UTC](https://forum.ansible.com/t/setting-path-in-user-crontab/15539/3 "2014-06-26T16:45:51Z")

</div>

In my application, I create a user specific crontab entry in /etc/cron.d/user. I then use the lineinfile module to set HOME=“/tmp” (insertbefore=BOF). From there on out, when using the cron module, I specify cron\_file=/etc/cron.d/user.

I think that’d work for your case…

---

<div class="post-metadata">

**Author:** ![Andrew\_Udvare](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@Andrew\_Udvare](https://forum.ansible.com/u/Andrew_Udvare)\
**Post date:** [July 9, 2014, 9:18am UTC](https://forum.ansible.com/t/setting-path-in-user-crontab/15539/4 "2014-07-09T09:18:34Z")

</div>

Depends on what cron implementation you are using. If vixie-cron, you can literally put PATH in the crontab line (not that I really recommend this). If cronie you can put environment variables at the top of crontab files but they apply to all commands there. This also works with vixie-cron.

If your cron is a really old one or extremely basic (or if you want to support basically every cron implementation out there), then you have to create a wrapper script that will be on the crontab line.

On the machine type you are targeting man 5 crontab and read all of it.
