Ansible - 如何在 --check 时打印跳过的任务名称?

问题描述 投票:0回答:1

当我使用

--check
选项运行 playbook 时,我仅看到
ok
changed
任务的名称。

TASK [playbook : taskN] ************************************************************************************************
ok: [host00.domain]

TASK [playbook : taskN+1] ************************************************************************************************
ok: [host00.domain]

TASK [playbook : taskN+2] ************************************************************************************************
changed: [host00.domain] => (item=item_stuff)

PLAY RECAP ************************************************************************************************
host00.domain         : ok=6    changed=2    unreachable=0    failed=0    skipped=2    rescued=0    ignored=0   

我看到了

skipped=2
,但是到底跳过了哪些任务?
-vvv
没有帮助。

跳过任务的示例:

tasks/main.yml

- import_tasks: taskF.yml
  when: "'host_group' in group_names"

tasks/taskF.yml

- name: test network
  shell: echo AAA
  tags: full, test
ansible ansible-2.x
1个回答
0
投票

根据文档

default
回调 – 默认 Ansible 屏幕输出 参数:
display_skipped_hosts
ansible.cfg
应该可以做到。

[defaults]
display_skipped_hosts   = yes

一个最小的例子

---
- hosts: localhost
  become: false
  gather_facts: false

  tasks:

  - import_tasks: taskF.yml
    when: true
- name: Test network
  shell: echo $(hostname)
  tags: full, test

通过

调用
ansible-playbook main.yml --check

将产生

的输出
PLAY [localhost] *********

TASK [Test network] ******
skipping: [localhost]

PLAY RECAP *******************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

由此配置为

[defaults]
display_skipped_hosts   = no

这会导致

PLAY [localhost] *********

PLAY RECAP *******************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0
© www.soinside.com 2019 - 2024. All rights reserved.