cron
ansible 2.2.0.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
set forks to 50
set remote_user to root
Running from Arch
Managing Debian and Arch
When trying to add an variable to crontab, the cron module crashes when the crontab for the user doesn't exist
How I found it:
- name: add mailto in crontab
cron:
env: true
name: MAILTO
value: [email protected]
Also reproducable with: ansible server -m cron
Crontab is created and the variable is set
Using /etc/ansible/ansible.cfg as config file
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc
_________________________
< PLAYBOOK: cron_test.yml >
-------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
1 plays in cron_test.yml
________________
< PLAY [servers] >
----------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
______________
< TASK [setup] >
--------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
Using module file /usr/lib/python2.7/site-packages/ansible/modules/core/system/setup.py
<server.example.com> ESTABLISH SSH CONNECTION FOR USER: root
<server.example.com> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/yannik/.ansible/cp/ansible-ssh-%h-%p-%r server.example.com '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1481749084.03-261788129351509 `" && echo ansible-tmp-1481749084.03-261788129351509="` echo $HOME/.ansible/tmp/ansible-tmp-1481749084.03-261788129351509 `" ) && sleep 0'"'"''
<server.example.com> PUT /tmp/tmpkmhzmG TO /root/.ansible/tmp/ansible-tmp-1481749084.03-261788129351509/setup.py
<server.example.com> SSH: EXEC sftp -b - -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/yannik/.ansible/cp/ansible-ssh-%h-%p-%r '[server.example.com]'
<server.example.com> ESTABLISH SSH CONNECTION FOR USER: root
<server.example.com> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/yannik/.ansible/cp/ansible-ssh-%h-%p-%r server.example.com '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1481749084.03-261788129351509/ /root/.ansible/tmp/ansible-tmp-1481749084.03-261788129351509/setup.py && sleep 0'"'"''
<server.example.com> ESTABLISH SSH CONNECTION FOR USER: root
<server.example.com> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/yannik/.ansible/cp/ansible-ssh-%h-%p-%r -tt server.example.com '/bin/sh -c '"'"'/usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1481749084.03-261788129351509/setup.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1481749084.03-261788129351509/" > /dev/null 2>&1 && sleep 0'"'"''
ok: [server.example.com]
______________________________
< TASK [add mailto in crontab] >
------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
task path: /home/yannik/ansible/cron_test.yml:8
Using module file /usr/lib/python2.7/site-packages/ansible/modules/core/system/cron.py
<server.example.com> ESTABLISH SSH CONNECTION FOR USER: root
<server.example.com> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/yannik/.ansible/cp/ansible-ssh-%h-%p-%r server.example.com '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1481749089.57-122565518806595 `" && echo ansible-tmp-1481749089.57-122565518806595="` echo $HOME/.ansible/tmp/ansible-tmp-1481749089.57-122565518806595 `" ) && sleep 0'"'"''
<server.example.com> PUT /tmp/tmpo5QPIc TO /root/.ansible/tmp/ansible-tmp-1481749089.57-122565518806595/cron.py
<server.example.com> SSH: EXEC sftp -b - -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/yannik/.ansible/cp/ansible-ssh-%h-%p-%r '[server.example.com]'
<server.example.com> ESTABLISH SSH CONNECTION FOR USER: root
<server.example.com> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/yannik/.ansible/cp/ansible-ssh-%h-%p-%r server.example.com '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1481749089.57-122565518806595/ /root/.ansible/tmp/ansible-tmp-1481749089.57-122565518806595/cron.py && sleep 0'"'"''
<server.example.com> ESTABLISH SSH CONNECTION FOR USER: root
<server.example.com> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/yannik/.ansible/cp/ansible-ssh-%h-%p-%r -tt server.example.com '/bin/sh -c '"'"'/usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1481749089.57-122565518806595/cron.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1481749089.57-122565518806595/" > /dev/null 2>&1 && sleep 0'"'"''
fatal: [server.example.com]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_name": "cron"
},
"module_stderr": "OpenSSH_7.3p1, OpenSSL 1.0.2j 26 Sep 2016\r\ndebug1: Reading configuration data /home/yannik/.ssh/config\r\ndebug1: /home/yannik/.ssh/config line 12: Applying options for server.example.com\r\ndebug3: kex names ok: [diffie-hellman-group1-sha1]\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 4951\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\nShared connection to server.example.com closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible_osseXT/ansible_module_cron.py\", line 703, in <module>\r\n main()\r\n File \"/tmp/ansible_osseXT/ansible_module_cron.py\", line 578, in main\r\n crontab = CronTab(module, user, cron_file)\r\n File \"/tmp/ansible_osseXT/ansible_module_cron.py\", line 236, in __init__\r\n self.read()\r\n File \"/tmp/ansible_osseXT/ansible_module_cron.py\", line 257, in read\r\n raise CronTabError(\"Unable to read crontab\")\r\n__main__.CronTabError: Unable to read crontab\r\n",
"msg": "MODULE FAILURE"
}
____________
< PLAY RECAP >
------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
server.example.com : ok=1 changed=0 unreachable=0 failed=1
OK, I just discovered that on the systems where this happens, cron is not installed.
Most helpful comment
OK, I just discovered that on the systems where this happens, cron is not installed.