ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Im having a problem with ansible while adding entry to crontab for user: user1.
Entry is added, however for some reason between execution time and a command, user1 is added.
Please see following result:
@NevemTeve - it must be done via ansible.
@pan64 - if I keep username (between time and command), cron job execution will fail. Once i manually remove username, it works.
It puzzles me from where ansible takes this user1???
My suggestions are :
you should use double quote only for variable values
Ex/
Code:
dest: /mnt/sync
or
dest: "{{ my_dest }}"
Why is your path pointing to a script and not a directory (/mnt/sync) ?
This is similar to touch a file, in your playbook this is useless because of the state
Thank you Marav for your reply and suggestions but the part of ansible code you mentioned works OK.
The problem is with the ansible code that inserts crontab entry (here):
Code:
- name: cron job to for script1.sh
cron:
name: script1
weekday: "1"
hour: "1"
cron_file: "/var/spool/cron/user1"
user: user1
job: "/mnt/sync/script1.sh"
Sorry, that was misleading for me. Never mind.
As I posted there are system jobs and user jobs. Now your playbook creates system jobs (with user info), but you need to create user job. Actually I think you need to omit cron_file too.
cron_file
string
If specified, uses this file instead of an individual user's crontab.
If this is a relative path, it is interpreted with respect to /etc/cron.d.
If it is absolute, it will typically be /etc/crontab.
Many linux distros expect (and some require) the filename portion to consist solely of upper- and lower-case letters, digits, underscores, and hyphens.
To use the cron_file parameter you must specify the user as well.
It expects any named cron file to either to be relative to /etc/cron.d or be /etc/crontab, both of which require a user.
You can see this with their examples
Code:
- name: Modifies the users crontab and doesn't need a username
cron:
name: "Auto update apt"
job: "apt-get update"
state: present
- name: Creates a cron file as /etc/cron.d/apt-update and needs a username
cron:
name: Auto update apt
user: root
job: "apt-get update"
cron_file: apt-update
state: present
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.