junior_h
junior_h

Reputation: 11

Ansible doesn't show tasks when including task file use "with_" loop

In ansible 2.1 there is loop_control feature that allow to use task includes + with_ loop and pass loop item variable to its tasks. Before run playbook, I use to check list tasks. But when use with_ loop + task include, I can't check list tasks inside include file. Currently I'm using ansible 2.1.2.0 and here is my code:

main.yml

- hosts: localhost
  connection: local
  vars:
    var1:
      - 1
      - 2
  tasks:
  - name: debuging 1
    debug: msg=debug1
  - include: task1.yml var1=test1
    with_items: "{{ var1 }}"
    loop_control:
      loop_var: var2
  - name: debuging 2
    debug: msg=debug2

task1.yml

- name: "task1-1"
  debug: msg=task1-1
- name: "task1-2"
  debug: msg=task1-2

run ansible

$ ansible-playbook main1.yml -vv --list-tasks
No config file found; using defaults
1 plays in playbooks/main1.yml

playbook: playbooks/main1.yml

play #1 (localhost): localhost  TAGS: []
  tasks:
    debuging 1  TAGS: []
    include TAGS: []
    debuging 2  TAGS: []

Moreover when I apply tags on tasks, it will make more difficult to verify the playbook because it can't be shown. I think, it's good if ansible can also list all task inside task include files as if task include without with_ loop. I expect that the output looks like

...
play #1 (localhost): localhost  TAGS: []
  tasks:
    debuging 1  TAGS: []
    tasks1-1    TAGS: []
    tasks1-2    TAGS: []
    debuging 2  TAGS: []
...

I don't know whether it's bug or not

Upvotes: 1

Views: 1223

Answers (1)

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68229

This behavior is an expected behavior. Please read Dynamic versus Static Includes.

Excerpt from that chapter:

When using dynamic includes, it is important to keep these limitations in mind:
- You cannot use notify to trigger a handler name which comes from a dynamic include.
- You cannot use --start-at-task to begin execution at a task inside a dynamic include.
- Tags which only exist inside a dynamic include will not show up in –list-tags output.
- Tasks which only exist inside a dynamic include will not show up in –list-tasks output.

Upvotes: 1

Related Questions