Ansible include task files based on conditional -


just getting ansible , want know if can include file in task main.yml based on variable passed in --extra-vars?

example;

main.yml -- role/tasks

# upload latest json s3 - include: upload-code.yml 

playbook.yml -- playbooks

- name: launch cloudformation stack   hosts: 127.0.0.1   connection: local   roles:     - launch.cloudformation 

as can see playbook.yml includes role , main.yml includes upload-code.yml

how can include upload-code.yml based on conditional below

ansible-playbook playbook.yml --extra-vars "include=upload"

you can applying when condition include task.

- include: upload-code.yml   when:     - include defined     - include == "upload" 

or, if have multiple include files use include part of name.

- include: "{{ include }}-code.yml"   when: include defined 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -