Cron module does not properly set SELinux context for user crontabs

I am having the same issue inserting crons into the root user’s crontab file according to this GitHub Issue

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

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

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!