Creating a cron job with Ansible (ERROR! 'cron' is not a valid attribute for a Play) I am relatively inexperienced when it comes to Ansible however I have previously created playbooks which will create a cron job successfully. For the life of me I cannot work out what is wrong with my .yml file.

I am receiving the below error when attempting to run my playbook locally with:

ansible-playbook -i "localhost," -c local crond.yml


ERROR! 'cron' is not a valid attribute for a Play

The error appears to have been in 
'/etc/ansible/cds/roles/backups/tasks/crond.yml': line 3, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- cron:
  ^ here


I have seen similar questions asked on SE/Ansible forums but to no avail. Any help/guidance would be much appreciated.

Here is my crond.yml file:

- cron:
    user: "root"
    minute: "30"
    hour: "02"
    job: '{{/usr/bin/rsync -avhz -e "ssh" --rsync-path="sudo rsync" -H --delete --numeric-ids &lt;ipaddress&gt;:"/data/rsnapshot-backups/&lt;ipaddress&gt;" /data/rsnapshot-backup}}'
    state: present
crond.yml in your example is not a playbook. It is a tasks file (list of tasks), while playbook is a list of plays.

A play must have hosts directive at minimum. Please see http://docs.ansible.com/ansible/latest/playbooks_intro.html#hosts-and-users

This is a playbook:

- hosts: localhost
  tasks:
    - cron:
        user: "root"
        minute: "30"
        hour: "02"
        job: '/usr/bin/rsync -avhz -e "ssh" --rsync-path="sudo rsync" -H --delete --numeric-ids &lt;ipaddress&gt;:"/data/rsnapshot-backups/&lt;ipaddress&gt;" /data/rsnapshot-backup'
        state: present