According the documentation cron
module – Manage cron.d
and crontab
entries, the given Examples and your current description as it is
How can I avoid myuser getting added
it is the expected behavior
TASK [Enable or disable cron] *****************************************
fatal: [localhost]: FAILED! => changed=false
msg: To use cron_file=... parameter you must specify user=... as well
and since it seems you are creating a cron file under /var/spool/cron/myuser
.
Please take note that a dedicated cron file is something different than an entry in a cron table file (crontab).
A minimal example like
---
- hosts: localhost
become: false
gather_facts: false
tasks:
- name: Enable or disable cron
cron:
cron_file: "/home/{{ ansible_user }}/test/cronfile"
user: "{{ ansible_user }}"
state: present
disabled: true
name: my cron
job: cron script
minute: "0"
hour: "4"
will result into a cron file of
cat cronfile
#Ansible: my cron
#0 4 * * * user cron script
or if disabled: false
of
0 4 * * * user cron script
To summarize, you can't avoid it and would need an other approach.
Further Readings
about
... you could to make sure the presence or absence of the cron file in example, but unfortunately there is almost no description of what you try to achieve.