---
- include: 1.yml
when: type == '1'
- include: 2.yml
when: type == '2'
---
- name: "1"
hosts: localhost
tasks:
- debug: msg="1"
---
- name: "2"
hosts: localhost
tasks:
- debug: msg="2"
ansible-playbook test.yml -e "type=1"
PLAY [1] **********************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [debug msg="1"] *********************************************************
ok: [localhost] => {
"msg": "1"
}
PLAY [2] **********************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [debug msg="2"] *********************************************************
ok: [localhost] => {
"msg": "2"
}
PLAY RECAP ********************************************************************
localhost : ok=4 changed=0 unreachable=0 failed=0