syntax error while using block module in ansible

I'm currently watching  Demo: Error Handling – Block Groups from the Red Hat Certified Specialist in Ansible Automation (EX407), and I have the following playbook:


- hosts: l1
become: yes
tasks:
- name: get file
block:
- get_url:
url: "http://somesite/indexd.php"
dest: "/tmp/index_file"
rescue:
- debug msg="The file doesn't exist!"
always:
- debug: msg="Play done!"


When I run it, I get the following error:


ERROR! 'url' is not a valid attribute for a Task

The error appears to have been in '/Users/vinci/NextCloud/redhatansible/block_error.yml': line 7, column 11, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

block:
- get_url:
^ here

This error can be suppressed as a warning using the "invalid_task_attribute_failed" configuration

I'm not sure what I'm doing wrong, as this is exactly the syntax I'm seeing in the video. 
If I indent "url" and "dest", then it says: "ERROR! A malformed block was encountered while loading rescue."

Any help is much appreciated.
  • post-author-pic
    Lethargos A
    12-20-2018

  • post-author-pic
    Lethargos A
    12-20-2018

    Just after posting I realised that I didn't write : after the first debug. Everthing worked afterwards. I wanted to delete the post, but I'm unable to. Maybe a moderator could do that for me. Thanks

  • post-author-pic
    Stosh O
    12-20-2018

    No worries.  Glad you were able to solve your issue!

Looking For Team Training?

Learn More