Tasks in a task file that should not have been included are being listed

3 views
Skip to first unread message

Mauricio Tavares

unread,
Nov 6, 2019, 5:57:14 AM11/6/19
to ansible...@googlegroups.com
My roles/test/tasks/main.yml file looks like this:
---
# test/tasks/main.yml

- include: users.yml
when: user_test|default(False)
- include: file.yml
when: file_test|default(False)
- include: string.yml
when: string_test|default(False)
- include: loop.yml
when: loop_test|default(False)

The playbook that runs my tests currently have only "user_test"
defined. Expected behaviour is that users.yml is included and the rest
ignored. However, when I run test (no verbose flags of any kind):

ansible-playbook test.yml --limit testmail

I see messages like this:

[...]
TASK [test : Create strings] **************************************************
*
skipping: [testmail]

TASK [test : debug] ***********************************************************
*
skipping: [testmail]

TASK [test : Edit strings] ****************************************************
*
skipping: [testmail]

TASK [test : debug] ***********************************************************
*
skipping: [testmail]

which are listing tasks inside string.yml. Yes, it is skipping said
tasks but I thought it would not try to peek at that task file to
begin with. Is that expected behaviour or I did something wrong?

Vladimir Botka

unread,
Nov 6, 2019, 6:56:43 AM11/6/19
to Mauricio Tavares, ansible...@googlegroups.com
On Wed, 6 Nov 2019 05:56:46 -0500
Mauricio Tavares <raub...@gmail.com> wrote:

> - include: string.yml
> when: string_test|default(False)
> [...]
> TASK [test : Create strings] **************************************
> *
> skipping: [testmail]
> [...]
> which are listing tasks inside string.yml. Yes, it is skipping said
> tasks but I thought it would not try to peek at that task file to
> begin with. Is that expected behaviour or I did something wrong?


Use *include_tasks* instead of *include*.

Quoting:"Prior to Ansible 2.4, only include was available and it behaved
differently depending on context". See "Including and Importing"
https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_includes.html#including-and-importing

Cheers,

-vlado
Reply all
Reply to author
Forward
0 new messages