git clone is not working in Cron jobs

Hello Team,

I want to clone the git repository using ansible Cron module. I am trying to change the local repository for every 5 mintes using Cron module in ansible playbook. For that i wrote the code as below.

The below cron job is not working for git clone.

  • cron:
    name: “download the git folder using cron jobs”
    minute: “5”
    job: ‘sudo “git clone --depth=1 --force=yes https://github.com/Msutapalli/openwhisk.git” > /home/ec2-user/siva/openw/’
    cron_file: “/etc/crontab”
    state: present
    user: ec2-user
    user: root

But for sample

  • cron:
    name: “Sample hello”
    minute: “5”
    job: ‘sudo echo " heloworld " > /home/ec2-user/hello.txt’
    cron_file: “/etc/crontab”
    state: present
    user: ec2-user
    user: root

It is working fine.

where i did wrong in my 'job: ’ command.

Thanks in advance

a few issues:

  • ‘user’ is defined twice?
  • you are sudo’ing from a cronjob - why not manipulate the target user’s cronjob directly?
  • the output of git is redirected to a directory, I guess you either meant to clone into this directory, or redirect the output to a file (output != repository location)

Dick

Quoting balubhai555 (balubhai555@gmail.com):

I want to clone the git repository using ansible Cron module.

So why not create a playbook that does this and run it from cron? :wink:

*The below cron job is not working for git clone*.
job: 'sudo "git clone --depth=1 --force=yes https://github.com/Msutapalli/openwhisk.git" > /home/ec2-user/siva/openw/'

Drop the double quotes.
Also, a filename seems to be missing in your stdout redirection.

$ sudo "git help"
sudo: git help: command not found

$ sudo git help
usage: git [--version] [--help] [-C <path>] [-c name=value]
[..]

But for sample
job: 'sudo echo " heloworld " > /home/ec2-user/hello.txt'
It is working fine.

Notice 'echo' is not in the double quotes.

-Sndr.

Yes Dick, You are right.

1.) ‘user’ defined twice because my intention is to use the cron job for both users.
2.) Yes, I tried without sudo, But no effect with sudo or without sudo’ing in the clone.
3.) Yes, you are right. I am trying to store the repository into those folder.

Can you suggest me more changes to work with cron with git clone.

Yes Dick, You are right.

1.) ‘user’ defined twice because my intention is to use the cron job for both users.

That’s unlikely to work. If you actually do want that, I suggest iterating over a list of users using ‘with_items’.
(If it does work then it needs documentation.)

2.) Yes, I tried without sudo, But no effect with sudo or without sudo’ing in the clone.

Don’t use it as it complicates things for no reason.

3.) Yes, you are right. I am trying to store the repository into those folder.

Can you suggest me more changes to work with cron with git clone.

cron schedules commands, and the ansible cron module is a convenient way to configure it (timing, user, etc).

The problem is that your command doesn’t work.
Scheduling something that doesn’t work has the same result: it still doesn’t work.
So fix your command first, and once it works you can try to schedule it.

Hint: make sure you are able to clone a git repository into a specific directory: https://git-scm.com/docs/git-clone

I’m not sure if repeatedly cloning a git repo is actually useful, so make sure you understand what the implications are of doing that (or come up with a different approach).

Dick