I have a main.yaml like below:
- import_playbook: 1.yaml
- import_playbook: 2.yaml
vars:
allow2: False
when: allow2
I want the playbook 2.yaml can be skipped totally (not try to execute any tasks inside 2.yaml).
But it looks all tasks in 2.yaml will be called but not executed.
File 1.yaml:
- name: Go1
hosts: test
gather_facts: false
tasks:
- debug: msg="Message from 1.yaml"
File 2.yaml:
- name: Go2
hosts: test
gather_facts: false
tasks:
- debug: msg="Message from 2.yaml"
The output is:
$ ansible-playbook main.yaml
PLAY [Go1] ***********
TASK [debug] *********
Thursday 05 October 2017 03:10:12 -0400 (0:00:00.116) 0:00:00.116 ******
ok: [test1] => {}
MSG:
Message from 1.yaml
PLAY [Go2] ************
TASK [debug] ************
Thursday 05 October 2017 03:10:12 -0400 (0:00:00.090) 0:00:00.206 ******
skipping: [test1]
The you can say the task in 2.yaml also was called but skipped.
But I want no any tasks will be called in 2.yaml.
Is it possible?
Ignoring failed commands By default Ansible stops executing tasks on a host when a task fails on that host. You can use ignore_errors to continue on in spite of the failure. The ignore_errors directive only works when the task is able to run and returns a value of 'failed'.
If you assign the never tag to a task or play, Ansible will skip that task or play unless you specifically request it ( --tags never ).
The default behavior is to pause with a prompt. You can use ctrl+c if you wish to advance a pause earlier than it is set to expire or if you need to abort a playbook run entirely. To continue early: press ctrl+c and then c . To abort a playbook: press ctrl+c and then a .
No, this is not possible this way.
Please see answer at serverfault about import/include difference.
import_playbook is static, so it's always done and when statements attached to everything inside it.
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