Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: tasks is not a legal parameter - Ansible playbook

In my playbook I have a conditional include statement to include a task:

  tasks:
    # Install Java if not present
  - name: Execute Java
    shell: java -version
    register: result
    ignore_errors: True

  - include: tasks/java.yml
    when: result | failed
    ...

When I execute playbook it give out an error:

user1@localhost:~ ansible-playbook tomcat.yml
ERROR: tasks is not a legal parameter in an Ansible task or handler

However when I replace this include statement with shell or something else, playbook runs as expected.... Ansible docs tells that task can be conditionally included, so why I am getting error here?

like image 456
Tariq Avatar asked Aug 04 '14 07:08

Tariq


1 Answers

Solution: You should leave out the "tasks:" part in the included file.

Why it fails: When you include, you are already in the tasks section so to Ansible it looks like:

- tasks:
    tasks:
      - name: https://www.digitalocean.com/pricing/
        ...
like image 127
Ramon de la Fuente Avatar answered Oct 02 '22 00:10

Ramon de la Fuente