Reputation: 2569
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?
Upvotes: 5
Views: 17236
Reputation: 779
This happens when you define "tasks" within "tasks"
Tasks definitions within tasks definitions can happen if you try to include another playbook that has a tasks definition in it.
Upvotes: 0
Reputation: 8343
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/
...
Upvotes: 15