git clone is not working in Cron jobs

557 views
Skip to first unread message

balubhai555

unread,
Apr 27, 2017, 10:01:35 AM4/27/17
to Ansible Project
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

Dick Visser

unread,
Apr 27, 2017, 11:44:39 AM4/27/17
to ansible...@googlegroups.com
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
 


--
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/0fe724ce-685f-45e2-963e-ddff09ed98c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Dick Visser
Sr. System & Network Engineer
GÉANT

Want to join us? We're hiring: https://www.geant.org/jobs

Sander Smeenk

unread,
Apr 27, 2017, 11:58:56 AM4/27/17
to Ansible Project
Quoting balubhai555 (balub...@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? ;)

> *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.
--
| A ship shipping ship shipping shipping ships!
| 4096R/20CC6CD2 - 6D40 1A20 B9AA 87D4 84C7 FBD6 F3A9 9442 20CC 6CD2

balubhai555

unread,
Apr 27, 2017, 1:33:45 PM4/27/17
to Ansible Project
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.

Dick Visser

unread,
Apr 27, 2017, 2:24:00 PM4/27/17
to ansible...@googlegroups.com
On Thu, 27 Apr 2017 at 19:33, balubhai555 <balub...@gmail.com> wrote:
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




--
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.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages