mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-10 14:05:07 +00:00
Feat: Add callback plugin print_task (#10087)
* Feat: Add callback plugin print_task
Prints task snippet to job output.
* Fix for failing tests
* Fix some pep8 formatting issues
* Updating DOCUMENTATION variable with version_added
* Set correct CALLBACK_NAME and fix warning with gather_facts
* Fix formatting again
* Update plugins/callback/print_task.py
* Update plugins/callback/print_task.py
* Add entry to BOTMETA.yml
* Use CSafeLoader and fallback to SafeLoader
* Change output function to self._display.display()
* Adding tests for community.general.print_task
* Adding EXAMPLES
* Apply suggestions from code review
---------
(cherry picked from commit b861850e1a)
Co-authored-by: Max Mitschke <demonpig@fastmail.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
132 lines
No EOL
4.9 KiB
YAML
132 lines
No EOL
4.9 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: community.general.print_task is not enabled
|
|
environment:
|
|
ANSIBLE_NOCOLOR: 'true'
|
|
ANSIBLE_FORCE_COLOR: 'false'
|
|
playbook: |
|
|
- hosts: testhost
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Sample task
|
|
debug:
|
|
msg: This is a test
|
|
expected_output: [
|
|
"",
|
|
"PLAY [testhost] ****************************************************************",
|
|
"",
|
|
"TASK [Sample task] *************************************************************",
|
|
"ok: [testhost] => {",
|
|
" \"msg\": \"This is a test\"",
|
|
"}",
|
|
"",
|
|
"PLAY RECAP *********************************************************************",
|
|
"testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
|
|
]
|
|
|
|
- name: community.general.print_task is enabled
|
|
environment:
|
|
ANSIBLE_NOCOLOR: 'true'
|
|
ANSIBLE_FORCE_COLOR: 'false'
|
|
ANSIBLE_CALLBACKS_ENABLED: 'community.general.print_task'
|
|
playbook: |
|
|
- hosts: testhost
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Sample task
|
|
debug:
|
|
msg: This is a test
|
|
expected_output: [
|
|
"",
|
|
"PLAY [testhost] ****************************************************************",
|
|
"",
|
|
"TASK [Sample task] *************************************************************",
|
|
"",
|
|
"- name: Sample task",
|
|
" debug:",
|
|
" msg: This is a test",
|
|
"",
|
|
"ok: [testhost] => {",
|
|
" \"msg\": \"This is a test\"",
|
|
"}",
|
|
"",
|
|
"PLAY RECAP *********************************************************************",
|
|
"testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
|
|
]
|
|
|
|
- name: Print with msg parameter on the same line
|
|
environment:
|
|
ANSIBLE_NOCOLOR: 'true'
|
|
ANSIBLE_FORCE_COLOR: 'false'
|
|
ANSIBLE_CALLBACKS_ENABLED: 'community.general.print_task'
|
|
playbook: |
|
|
- hosts: testhost
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Sample task
|
|
debug: msg="This is a test"
|
|
expected_output: [
|
|
"",
|
|
"PLAY [testhost] ****************************************************************",
|
|
"",
|
|
"TASK [Sample task] *************************************************************",
|
|
"",
|
|
"- name: Sample task",
|
|
" debug: msg=\"This is a test\"",
|
|
"",
|
|
"ok: [testhost] => {",
|
|
" \"msg\": \"This is a test\"",
|
|
"}",
|
|
"",
|
|
"PLAY RECAP *********************************************************************",
|
|
"testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
|
|
]
|
|
|
|
- name: Task with additional parameters
|
|
environment:
|
|
ANSIBLE_NOCOLOR: 'true'
|
|
ANSIBLE_FORCE_COLOR: 'false'
|
|
ANSIBLE_CALLBACKS_ENABLED: 'community.general.print_task'
|
|
playbook: |
|
|
- hosts: testhost
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Sample task
|
|
when: True
|
|
vars:
|
|
test_var: "Hello World"
|
|
debug:
|
|
var: test_var
|
|
expected_output: [
|
|
"",
|
|
"PLAY [testhost] ****************************************************************",
|
|
"",
|
|
"TASK [Sample task] *************************************************************",
|
|
"",
|
|
"- name: Sample task",
|
|
" when: true",
|
|
" vars:",
|
|
" test_var: Hello World",
|
|
" debug:",
|
|
" var: test_var",
|
|
"",
|
|
"ok: [testhost] => {",
|
|
" \"test_var\": \"Hello World\"",
|
|
"}",
|
|
"",
|
|
"PLAY RECAP *********************************************************************",
|
|
"testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
|
|
] |