Got bug in case when module is run as uprivileged user: it always fails because cron requires sudo when -u option is specified.
When user: parameter is not set, cronvar tries to make changes for root.
So I made it behaves exactly like cron module when handling self.user.
playbook:
$ cat a.yml
---
- hosts: ansible
tasks:
- name: Add var to crontab
cronvar:
name: "TEST"
value: "Test"
before:
Using /home/michael/.ansible.cfg as config file
PLAYBOOK: a.yml ****************************************************************
1 plays in a.yml
PLAY [ansible] *****************************************************************
TASK [setup] *******************************************************************
...
ok: [localhost]
TASK [Add var to crontab] ******************************************************
task path: /home/michael/repos/ansible/a.yml:4
...
fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"backup": false,
"cron_file": null,
"insertafter": null,
"insertbefore": null,
"name": "TEST",
"state": "present",
"user": null,
"value": "Test"
},
"module_name": "cronvar"
},
"msg": "must be privileged to use -u\n"
}
to retry, use: --limit @/home/michael/repos/ansible/a.retry
PLAY RECAP *********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1
after:
PLAY [ansible] ******************************************************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************************************
ok: [localhost]
TASK [Add var to crontab] *******************************************************************************************************************************************************************
changed: [localhost]
PLAY RECAP **********************************************************************************************************************************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0
ISSUE TYPE
COMPONENT NAME
ANSIBLE VERSION
SUMMARY
Got bug in case when module is run as uprivileged user: it always fails because cron requires sudo when
-u
option is specified. Whenuser:
parameter is not set, cronvar tries to make changes for root.So I made it behaves exactly like cron module when handling self.user.
playbook:
before:
after: