# credentials problem when running ansible-pull from cron

**URL:** <https://forum.ansible.com/t/credentials-problem-when-running-ansible-pull-from-cron/14034>\
**Category:** Ansible Project\
**Created:** [November 29, 2013, 5:19pm UTC](https://forum.ansible.com/t/credentials-problem-when-running-ansible-pull-from-cron/14034 "2013-11-29T17:19:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas\_G](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Nicolas\_G](https://forum.ansible.com/u/Nicolas_G)\
**Post date:** [November 29, 2013, 5:19pm UTC](https://forum.ansible.com/t/credentials-problem-when-running-ansible-pull-from-cron/14034/1 "2013-11-29T17:19:52Z")

</div>

Hi All,

This is a simple playbook I have to test the S3 module which is working fine but I’m having problems when I run the same in pull mode from cron:

# s3example.yml

---

<div class="post-metadata">

**Author:** ![Krzysztof\_Warzecha](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@Krzysztof\_Warzecha](https://forum.ansible.com/u/Krzysztof_Warzecha)\
**Post date:** [December 3, 2013, 4:32pm UTC](https://forum.ansible.com/t/credentials-problem-when-running-ansible-pull-from-cron/14034/2 "2013-12-03T16:32:30Z")

</div>

~/.bashrc will not be sourced from cron task. .bashrc is sourced only  
when bash is started as interactive shell (see man bash), but cron  
tasks are started with sh -c (not bash nor interactive).

You can source your .bashrc manually or you can setup your  
AWS\_ACCESS\_KEY\_ID and AWS\_SECRET\_ACCESS\_KEY:

\*/5 \* \* \* \* ...; AWS\_ACCESS\_KEY\_ID=id AWS\_SECRET\_ACCESS\_KEY=secret  
ansible-pull ...

or:

\*/5 \* \* \* \* ...; source /path/to/your/.bashrc; ansible-pull ...

---

<div class="post-metadata">

**Author:** ![Nicolas\_G](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Nicolas\_G](https://forum.ansible.com/u/Nicolas_G)\
**Post date:** [December 4, 2013, 10:46am UTC](https://forum.ansible.com/t/credentials-problem-when-running-ansible-pull-from-cron/14034/3 "2013-12-04T10:46:14Z")

</div>

Thanks for the reply Krzysztof.

The problem is I’m using this approach on new Amazon EC2 instances and the only thing I have baked in the AMI along with Ansible installation and the ansible-pull cron is the ssh git in order to access the git server.

Therefore the AWS credentials are been checkout from git after the cronjob starts so I can’t know or specify them before the cronjob. As a temporary solution I have the AWS credentials in every S3 task as an argument but still I don’t think this is the best way to do it…

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [December 4, 2013, 1:53pm UTC](https://forum.ansible.com/t/credentials-problem-when-running-ansible-pull-from-cron/14034/4 "2013-12-04T13:53:12Z")

</div>

There are a couple ways to provide credentials to the ec2 modules / boto ... [https://gist.github.com/jctanner/7467100#credentials](https://gist.github.com/jctanner/7467100#credentials)

1) IAM roles  
2) boto config files  
3) create vars via the password lookup [http://www.ansibleworks.com/docs/playbooks\_lookups.html#the-password-lookup](http://www.ansibleworks.com/docs/playbooks_lookups.html#the-password-lookup)
