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?
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/
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With