# How to run an Ansible shell script from a Cron job?

**URL:** <https://forum.ansible.com/t/how-to-run-an-ansible-shell-script-from-a-cron-job/11973>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [October 12, 2012, 3:46pm UTC](https://forum.ansible.com/t/how-to-run-an-ansible-shell-script-from-a-cron-job/11973 "2012-10-12T15:46:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seth\_Vidal](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@Seth\_Vidal](https://forum.ansible.com/u/Seth_Vidal)\
**Post date:** [October 12, 2012, 3:46pm UTC](https://forum.ansible.com/t/how-to-run-an-ansible-shell-script-from-a-cron-job/11973/1 "2012-10-12T15:46:30Z")

</div>

So here is what I roughly intend:

# ssh-agent -s \> root-ssh-info  
# source root-ssh-info  
# ssh-add  
# \> inputpw  
# logout

cron job runs as root  
looks for /root/root-ssh-info and sources it  
can now run ansible as usual.

Yes - it means the first time your admin box boots up you need to input that password, etc but that's not the end of the world, I don't think.

-sv

---

<div class="post-metadata">

**Author:** ![Nigel\_Metheringham](https://avatars.discourse-cdn.com/v4/letter/n/3ec8ea/32.png) [@Nigel\_Metheringham](https://forum.ansible.com/u/Nigel_Metheringham)\
**Post date:** [October 12, 2012, 3:55pm UTC](https://forum.ansible.com/t/how-to-run-an-ansible-shell-script-from-a-cron-job/11973/2 "2012-10-12T15:55:06Z")

</div>

Co-incidentally I had mailed Seth about this only an hour or two ago...

Looks like one way of handling this problem is keychain:-  
&nbsp;&nbsp;[https://github.com/funtoo/keychain](https://github.com/funtoo/keychain)

Same idea, just a script around the packaging of it.

&nbsp;&nbsp;Nigel.

---

<div class="post-metadata">

**Author:** ![Seth\_Vidal](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@Seth\_Vidal](https://forum.ansible.com/u/Seth_Vidal)\
**Post date:** [October 12, 2012, 4:09pm UTC](https://forum.ansible.com/t/how-to-run-an-ansible-shell-script-from-a-cron-job/11973/3 "2012-10-12T16:09:28Z")

</div>

I don't have any problem with that script - looks like a whole lot of shell script - 1400 lines worth. I'll need to read through it.

Seems kinda unmaintained which worries me.

A simple ssh-agent + ssh-add seems pretty straightforward to me - but maybe there's a lot I'm overlooking. I'll read keychain and check.

-sv

---

<div class="post-metadata">

**Author:** ![Greenman](https://avatars.discourse-cdn.com/v4/letter/g/7cd45c/32.png) [@Greenman](https://forum.ansible.com/u/Greenman)\
**Post date:** [October 12, 2012, 6:46pm UTC](https://forum.ansible.com/t/how-to-run-an-ansible-shell-script-from-a-cron-job/11973/4 "2012-10-12T18:46:18Z")

</div>

Thanks all,

Keychain worked a treat.

Thanks,  
G

---

<div class="post-metadata">

**Author:** ![Nigel\_Metheringham](https://avatars.discourse-cdn.com/v4/letter/n/3ec8ea/32.png) [@Nigel\_Metheringham](https://forum.ansible.com/u/Nigel_Metheringham)\
**Post date:** [October 12, 2012, 7:51pm UTC](https://forum.ansible.com/t/how-to-run-an-ansible-shell-script-from-a-cron-job/11973/5 "2012-10-12T19:51:13Z")

</div>

Seth Vidal wrote:

> I don't have any problem with that script - looks like a whole lot of  
> shell script - 1400 lines worth. I'll need to read through it.

Its definitely pretty big...

> Seems kinda unmaintained which worries me.

I'm not so worried about that - its been around for a dozen years, with  
some reworking during that time, but has settled down to a very low rate  
of churn... but then its a fairly limited defined problem, and ssh-agent  
etc has not had a lot of churn in functionality either.

&nbsp;&nbsp;Nigel.
