# Cron module does not properly set SELinux context for user crontabs

**URL:** <https://forum.ansible.com/t/cron-module-does-not-properly-set-selinux-context-for-user-crontabs/23505>\
**Category:** Ansible Project\
**Created:** [January 19, 2017, 5:06pm UTC](https://forum.ansible.com/t/cron-module-does-not-properly-set-selinux-context-for-user-crontabs/23505 "2017-01-19T17:06:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeffrey\_Wen](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@Jeffrey\_Wen](https://forum.ansible.com/u/Jeffrey_Wen)\
**Post date:** [January 19, 2017, 5:06pm UTC](https://forum.ansible.com/t/cron-module-does-not-properly-set-selinux-context-for-user-crontabs/23505/1 "2017-01-19T17:06:31Z")

</div>

I am having the same issue inserting crons into the root user’s crontab file according to this [GitHub Issue](https://github.com/ansible/ansible-modules-core/issues/4511)

I am using ansible 2.3.0 … so shouldn’t my version include the commit that fixed this issue?

The exact error I am getting is:

`

fatal: [machine1]: FAILED! =\> {“changed”: false, “failed”: true, “module\_stderr”: “Shared connection to 127.0.0.1 closed.\r\n”, “module\_stdout”: “Traceback (most recent call last):\r\n File  
"/tmp/ansible\_TP4o\_l/ansible\_module\_cron.py", line 773, in \r\n main()\r\n File "/tmp/ansible\_TP4o\_l/ansible\_module\_cron.py", line 741, in main\r\n crontab.write()\r\n Fil  
e "/tmp/ansible\_TP4o\_l/ansible\_module\_cron.py", line 345, in write\r\n selinux.selinux\_lsetfilecon\_default(self.cron\_file)\r\nOSError: [Errno 14] Bad address\r\n”, “msg”: "MODULE FAILURE  
"}

`

What is happening now

1. The cron gets inserted into the root user’s crontab & produces that error above

2. I run the playbook again, and the error disappears (changes from **fatal:** to **ok:** )

3. I check root user’s crontab and the cron is there

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 19, 2017, 8:48pm UTC](https://forum.ansible.com/t/cron-module-does-not-properly-set-selinux-context-for-user-crontabs/23505/2 "2017-01-19T20:48:13Z")

</div>

2.3 has not been released yet, so it depends on which at commit your copy was pulled down from.

---

<div class="post-metadata">

**Author:** ![Jeffrey\_Wen](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@Jeffrey\_Wen](https://forum.ansible.com/u/Jeffrey_Wen)\
**Post date:** [January 19, 2017, 9:46pm UTC](https://forum.ansible.com/t/cron-module-does-not-properly-set-selinux-context-for-user-crontabs/23505/3 "2017-01-19T21:46:04Z")

</div>

Hi Brian,

I actually downgraded from 2.3.0 because my AUR repository did not have any newer updates.

I went to the stable release of 2.2.1 and my cron error is gone!
