setting PATH in user crontab

841 views
Skip to first unread message

Christine Spang

unread,
Jun 24, 2014, 5:40:50 PM6/24/14
to ansible...@googlegroups.com
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?

Michael DeHaan

unread,
Jun 26, 2014, 9:24:33 AM6/26/14
to ansible...@googlegroups.com
I don't see why you think it would be looking in /usr/local/bin as you have hard coded the path above.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d7c433e5-c563-48bc-be6f-b5fb89821b99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Scott Sturdivant

unread,
Jun 26, 2014, 12:46:16 PM6/26/14
to ansible...@googlegroups.com
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...


Andrew Udvare

unread,
Jul 9, 2014, 5:18:34 AM7/9/14
to ansible...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages