Hi Bob, On 05.08.19 23:21, Bob Tanner wrote: > Simple tasks, where I want the "Remote git configuration" task to only be > run when apache2_configuration == 'git' > > I do not understand why import_tasks: or include: is importing/including > remote-git.yml when apache2_configuration is not equal to git. > > Any help? >
So for me the following happens: When the when condition is false import_tasks still imports the tasks file, but skips all tasks in it. include_tasks on the other hand is skipped as a task itself. include without the _tasks (which you shouldn't use anymore) behaves a lot like import_tasks in this case. If you want it to behave like include_tasks, you'll have to set the static: no option to the include task. If you look at the documentation, it's in the examples: https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/utilities/logic/import_tasks.py#L58 https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/utilities/logic/include_tasks.py#L70 https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/utilities/logic/include.py#L79 Playbook: --- - hosts: localhost roles: - foobar Role: --- # foobar/tasks/main.yml - debug: var: config - import_tasks: foo.yml when: config == 'git' - include_tasks: foo.yml when: config == 'nogit' - debug: msg: 'End' --- # foobar/tasks/foo.yml - debug: msg: ABCDE ------------------------ ansible-playbook test.yml -e config=abc PLAY [localhost] ***************************** TASK [Gathering Facts] *********************** ok: [localhost] TASK [foobar : debug] ************************ ok: [localhost] => { "config": "abc" } TASK [foobar : debug] ************************ skipping: [localhost] TASK [foobar : include_tasks] **************** skipping: [localhost] TASK [foobar : debug] ************************ ok: [localhost] => { "msg": "End" } PLAY RECAP [...] Sebastian -- Sebastian Meyer Linux Consultant & Trainer Mail: [email protected] B1 Systems GmbH Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537 -- Deutsche OpenStack Tage 2019 -- 10% Rabatt auf den Ticketpreis ---- ------------------------ https://openstack-tage.de (Code DOST-B1) ---- -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/03758fba-ed8d-142a-2403-b52dd77189d5%40b1-systems.de.
