mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-06-28 23:19:33 +00:00
* fix(counter_enabled): display output for looped tasks with delegate_to Implement v2_runner_item_on_ok, v2_runner_item_on_failed, and v2_runner_item_on_skipped so that looped tasks (including those using delegate_to: localhost) produce visible output. Also extract _host_label, _display_result_ok, _display_result_failed, and _display_result_skipped helpers to eliminate repeated delegation and message-building logic across the callback methods. Fixes #8187 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * changelog(counter_enabled): add fragment for PR #12067 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * test(counter_enabled): add integration tests, adjust _host_label Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * test(counter_enabled): migrate integration tests to callback test framework Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * test(counter_enabled): fix integration tests to use set_fact instead of debug Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
102 lines
4.3 KiB
YAML
102 lines
4.3 KiB
YAML
---
|
|
####################################################################
|
|
# WARNING: These are designed specifically for Ansible tests #
|
|
# and should not be used as examples of how to write Ansible roles #
|
|
####################################################################
|
|
|
|
# Copyright (c) Ansible Project
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
- name: Run tests
|
|
include_role:
|
|
name: callback
|
|
vars:
|
|
tests:
|
|
- name: Task and host counters shown in N/M format
|
|
environment:
|
|
ANSIBLE_NOCOLOR: 'true'
|
|
ANSIBLE_FORCE_COLOR: 'false'
|
|
ANSIBLE_STDOUT_CALLBACK: community.general.counter_enabled
|
|
playbook: |
|
|
- hosts: testhost
|
|
gather_facts: false
|
|
tasks:
|
|
- name: First task
|
|
set_fact:
|
|
counter_test: first
|
|
- name: Second task
|
|
set_fact:
|
|
counter_test: second
|
|
expected_output:
|
|
- ""
|
|
- "PLAY [testhost] ****************************************************************"
|
|
- ""
|
|
- "TASK 1/2 [First task] **********************************************************"
|
|
- "ok: 1/1 [testhost]"
|
|
- ""
|
|
- "TASK 2/2 [Second task] *********************************************************"
|
|
- "ok: 1/1 [testhost]"
|
|
- ""
|
|
- "PLAY RECAP *********************************************************************"
|
|
- "testhost : ok=2 changed=0 unreachable=0 failed=0 rescued=0 ignored=0 "
|
|
|
|
- name: Loop task items are displayed (regression for issue 8187)
|
|
environment:
|
|
ANSIBLE_NOCOLOR: 'true'
|
|
ANSIBLE_FORCE_COLOR: 'false'
|
|
ANSIBLE_STDOUT_CALLBACK: community.general.counter_enabled
|
|
playbook: !unsafe |
|
|
- hosts: testhost
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Loop task
|
|
set_fact:
|
|
dummy_fact: "{{ item }}"
|
|
loop:
|
|
- item_a
|
|
- item_b
|
|
- item_c
|
|
expected_output:
|
|
- ""
|
|
- "PLAY [testhost] ****************************************************************"
|
|
- ""
|
|
- "TASK 1/1 [Loop task] ***********************************************************"
|
|
- "ok: [testhost] => (item=item_a)"
|
|
- "ok: [testhost] => (item=item_b)"
|
|
- "ok: [testhost] => (item=item_c)"
|
|
- ""
|
|
- "PLAY RECAP *********************************************************************"
|
|
- "testhost : ok=1 changed=0 unreachable=0 failed=0 rescued=0 ignored=0 "
|
|
|
|
- name: Delegated loop task items show delegation target (regression for issue 8187)
|
|
environment:
|
|
ANSIBLE_NOCOLOR: 'true'
|
|
ANSIBLE_FORCE_COLOR: 'false'
|
|
ANSIBLE_STDOUT_CALLBACK: community.general.counter_enabled
|
|
playbook: !unsafe |
|
|
- hosts: testhost
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Delegated loop task
|
|
set_fact:
|
|
dummy_fact: "{{ item }}"
|
|
loop:
|
|
- item_a
|
|
- item_b
|
|
- item_c
|
|
delegate_to: localhost
|
|
expected_output:
|
|
- ""
|
|
- "PLAY [testhost] ****************************************************************"
|
|
- ""
|
|
- "TASK 1/1 [Delegated loop task] *************************************************"
|
|
- - "ok: [testhost -> localhost] => (item=item_a)"
|
|
- "ok: [testhost -> localhost(127.0.0.1)] => (item=item_a)"
|
|
- - "ok: [testhost -> localhost] => (item=item_b)"
|
|
- "ok: [testhost -> localhost(127.0.0.1)] => (item=item_b)"
|
|
- - "ok: [testhost -> localhost] => (item=item_c)"
|
|
- "ok: [testhost -> localhost(127.0.0.1)] => (item=item_c)"
|
|
- ""
|
|
- "PLAY RECAP *********************************************************************"
|
|
- "testhost : ok=1 changed=0 unreachable=0 failed=0 rescued=0 ignored=0 "
|