W3cubDocs

/Ansible

community.general.diy – Customize the output

Note

This plugin is part of the community.general collection (version 3.8.1).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general.

To use it in a playbook, specify: community.general.diy.

New in version 0.2.0: of community.general

Synopsis

  • Callback plugin that allows you to supply your own custom callback templates to be output.

Requirements

The below requirements are needed on the local controller node that executes this callback.

  • set as stdout_callback in configuration

Parameters

Parameter Choices/Defaults Configuration Comments
check_mode_markers
boolean
added in 2.9 of ansible.builtin
    Choices:
  • no
  • yes
ini entries:

[defaults]
check_mode_markers = no

env:ANSIBLE_CHECK_MODE_MARKERS
Toggle to control displaying markers when running in check mode.
The markers are DRY RUN at the beggining and ending of playbook execution (when calling ansible-playbook --check) and CHECK MODE as a suffix at every play and task that is run in check mode.
display_failed_stderr
boolean
added in 2.7 of ansible.builtin
    Choices:
  • no
  • yes
ini entries:

[defaults]
display_failed_stderr = no

env:ANSIBLE_DISPLAY_FAILED_STDERR
Toggle to control whether failed and unreachable tasks are displayed to STDERR (vs. STDOUT)
display_ok_hosts
boolean
added in 2.7 of ansible.builtin
    Choices:
  • no
  • yes
ini entries:

[defaults]
display_ok_hosts = yes

env:ANSIBLE_DISPLAY_OK_HOSTS
Toggle to control displaying 'ok' task/host results in a task
display_skipped_hosts
boolean
    Choices:
  • no
  • yes
ini entries:

[defaults]
display_skipped_hosts = yes

env:DISPLAY_SKIPPED_HOSTS
Removed in: version 2.12 of ansible.builtin
Why: environment variables without "ANSIBLE_" prefix are deprecated
Alternative: the "ANSIBLE_DISPLAY_SKIPPED_HOSTS" environment variable
env:ANSIBLE_DISPLAY_SKIPPED_HOSTS
Toggle to control displaying skipped task/host results in a task
on_any_msg
string
ini entries:

[callback_diy]
on_any_msg = None

env:ANSIBLE_CALLBACK_DIY_ON_ANY_MSG
var: ansible_callback_diy_on_any_msg
Output to be used for callback on_any.
on_any_msg_color
string
ini entries:

[callback_diy]
on_any_msg_color = None

env:ANSIBLE_CALLBACK_DIY_ON_ANY_MSG_COLOR
var: ansible_callback_diy_on_any_msg_color
Output color to be used for on_any_msg.
Template should render a valid color value.
on_file_diff_msg
string
ini entries:

[callback_diy]
on_file_diff_msg = None

env:ANSIBLE_CALLBACK_DIY_ON_FILE_DIFF_MSG
var: ansible_callback_diy_on_file_diff_msg
Output to be used for callback on_file_diff.
on_file_diff_msg_color
string
ini entries:

[callback_diy]
on_file_diff_msg_color = None

env:ANSIBLE_CALLBACK_DIY_ON_FILE_DIFF_MSG_COLOR
var: ansible_callback_diy_on_file_diff_msg_color
Output color to be used for on_file_diff_msg.
Template should render a valid color value.
playbook_on_handler_task_start_msg
string
ini entries:

[callback_diy]
playbook_on_handler_task_start_msg = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_HANDLER_TASK_START_MSG
var: ansible_callback_diy_playbook_on_handler_task_start_msg
Output to be used for callback playbook_on_handler_task_start.
playbook_on_handler_task_start_msg_color
string
ini entries:

[callback_diy]
playbook_on_handler_task_start_msg_color = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_HANDLER_TASK_START_MSG_COLOR
var: ansible_callback_diy_playbook_on_handler_task_start_msg_color
Output color to be used for playbook_on_handler_task_start_msg.
Template should render a valid color value.
playbook_on_include_msg
string
ini entries:

[callback_diy]
playbook_on_include_msg = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_INCLUDE_MSG
var: ansible_callback_diy_playbook_on_include_msg
Output to be used for callback playbook_on_include.
playbook_on_include_msg_color
string
ini entries:

[callback_diy]
playbook_on_include_msg_color = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_INCLUDE_MSG_COLOR
var: ansible_callback_diy_playbook_on_include_msg_color
Output color to be used for playbook_on_include_msg.
Template should render a valid color value.
playbook_on_no_hosts_matched_msg
string
ini entries:

[callback_diy]
playbook_on_no_hosts_matched_msg = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_NO_HOSTS_MATCHED_MSG
var: ansible_callback_diy_playbook_on_no_hosts_matched_msg
Output to be used for callback playbook_on_no_hosts_matched.
playbook_on_no_hosts_matched_msg_color
string
ini entries:

[callback_diy]
playbook_on_no_hosts_matched_msg_color = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_NO_HOSTS_MATCHED_MSG_COLOR
var: ansible_callback_diy_playbook_on_no_hosts_matched_msg_color
Output color to be used for playbook_on_no_hosts_matched_msg.
Template should render a valid color value.
playbook_on_no_hosts_remaining_msg
string
ini entries:

[callback_diy]
playbook_on_no_hosts_remaining_msg = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_NO_HOSTS_REMAINING_MSG
var: ansible_callback_diy_playbook_on_no_hosts_remaining_msg
Output to be used for callback playbook_on_no_hosts_remaining.
playbook_on_no_hosts_remaining_msg_color
string
ini entries:

[callback_diy]
playbook_on_no_hosts_remaining_msg_color = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_NO_HOSTS_REMAINING_MSG_COLOR
var: ansible_callback_diy_playbook_on_no_hosts_remaining_msg_color
Output color to be used for playbook_on_no_hosts_remaining_msg.
Template should render a valid color value.
playbook_on_notify_msg
string
ini entries:

[callback_diy]
playbook_on_notify_msg = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_NOTIFY_MSG
var: ansible_callback_diy_playbook_on_notify_msg
Output to be used for callback playbook_on_notify.
playbook_on_notify_msg_color
string
ini entries:

[callback_diy]
playbook_on_notify_msg_color = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_NOTIFY_MSG_COLOR
var: ansible_callback_diy_playbook_on_notify_msg_color
Output color to be used for playbook_on_notify_msg.
Template should render a valid color value.
playbook_on_play_start_msg
string
ini entries:

[callback_diy]
playbook_on_play_start_msg = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_PLAY_START_MSG
var: ansible_callback_diy_playbook_on_play_start_msg
Output to be used for callback playbook_on_play_start.
playbook_on_play_start_msg_color
string
ini entries:

[callback_diy]
playbook_on_play_start_msg_color = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_PLAY_START_MSG_COLOR
var: ansible_callback_diy_playbook_on_play_start_msg_color
Output color to be used for playbook_on_play_start_msg.
Template should render a valid color value.
playbook_on_setup_msg
string
ini entries:

[callback_diy]
playbook_on_setup_msg = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_SETUP_MSG
var: ansible_callback_diy_playbook_on_setup_msg
Output to be used for callback playbook_on_setup.
playbook_on_setup_msg_color
string
ini entries:

[callback_diy]
playbook_on_setup_msg_color = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_SETUP_MSG_COLOR
var: ansible_callback_diy_playbook_on_setup_msg_color
Output color to be used for playbook_on_setup_msg.
Template should render a valid color value.
playbook_on_start_msg
string
ini entries:

[callback_diy]
playbook_on_start_msg = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_START_MSG
var: ansible_callback_diy_playbook_on_start_msg
Output to be used for callback playbook_on_start.
playbook_on_start_msg_color
string
ini entries:

[callback_diy]
playbook_on_start_msg_color = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_START_MSG_COLOR
var: ansible_callback_diy_playbook_on_start_msg_color
Output color to be used for playbook_on_start_msg.
Template should render a valid color value.
playbook_on_stats_msg
string
ini entries:

[callback_diy]
playbook_on_stats_msg = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_STATS_MSG
var: ansible_callback_diy_playbook_on_stats_msg
Output to be used for callback playbook_on_stats.
playbook_on_stats_msg_color
string
ini entries:

[callback_diy]
playbook_on_stats_msg_color = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_STATS_MSG_COLOR
var: ansible_callback_diy_playbook_on_stats_msg_color
Output color to be used for playbook_on_stats_msg.
Template should render a valid color value.
playbook_on_task_start_msg
string
ini entries:

[callback_diy]
playbook_on_task_start_msg = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_TASK_START_MSG
var: ansible_callback_diy_playbook_on_task_start_msg
Output to be used for callback playbook_on_task_start.
playbook_on_task_start_msg_color
string
ini entries:

[callback_diy]
playbook_on_task_start_msg_color = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_TASK_START_MSG_COLOR
var: ansible_callback_diy_playbook_on_task_start_msg_color
Output color to be used for playbook_on_task_start_msg.
Template should render a valid color value.
playbook_on_vars_prompt_msg
string
ini entries:

[callback_diy]
playbook_on_vars_prompt_msg = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_VARS_PROMPT_MSG
var: ansible_callback_diy_playbook_on_vars_prompt_msg
Output to be used for callback playbook_on_vars_prompt.
playbook_on_vars_prompt_msg_color
string
ini entries:

[callback_diy]
playbook_on_vars_prompt_msg_color = None

env:ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_VARS_PROMPT_MSG_COLOR
var: ansible_callback_diy_playbook_on_vars_prompt_msg_color
Output color to be used for playbook_on_vars_prompt_msg.
Template should render a valid color value.
runner_item_on_failed_msg
string
ini entries:

[callback_diy]
runner_item_on_failed_msg = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ITEM_ON_FAILED_MSG
var: ansible_callback_diy_runner_item_on_failed_msg
Output to be used for callback runner_item_on_failed.
runner_item_on_failed_msg_color
string
ini entries:

[callback_diy]
runner_item_on_failed_msg_color = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ITEM_ON_FAILED_MSG_COLOR
var: ansible_callback_diy_runner_item_on_failed_msg_color
Output color to be used for runner_item_on_failed_msg.
Template should render a valid color value.
runner_item_on_ok_msg
string
ini entries:

[callback_diy]
runner_item_on_ok_msg = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ITEM_ON_OK_MSG
var: ansible_callback_diy_runner_item_on_ok_msg
Output to be used for callback runner_item_on_ok.
runner_item_on_ok_msg_color
string
ini entries:

[callback_diy]
runner_item_on_ok_msg_color = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ITEM_ON_OK_MSG_COLOR
var: ansible_callback_diy_runner_item_on_ok_msg_color
Output color to be used for runner_item_on_ok_msg.
Template should render a valid color value.
runner_item_on_skipped_msg
string
ini entries:

[callback_diy]
runner_item_on_skipped_msg = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ITEM_ON_SKIPPED_MSG
var: ansible_callback_diy_runner_item_on_skipped_msg
Output to be used for callback runner_item_on_skipped.
runner_item_on_skipped_msg_color
string
ini entries:

[callback_diy]
runner_item_on_skipped_msg_color = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ITEM_ON_SKIPPED_MSG_COLOR
var: ansible_callback_diy_runner_item_on_skipped_msg_color
Output color to be used for runner_item_on_skipped_msg.
Template should render a valid color value.
runner_on_failed_msg
string
ini entries:

[callback_diy]
runner_on_failed_msg = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ON_FAILED_MSG
var: ansible_callback_diy_runner_on_failed_msg
Output to be used for callback runner_on_failed.
runner_on_failed_msg_color
string
ini entries:

[callback_diy]
runner_on_failed_msg_color = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ON_FAILED_MSG_COLOR
var: ansible_callback_diy_runner_on_failed_msg_color
Output color to be used for runner_on_failed_msg.
Template should render a valid color value.
runner_on_no_hosts_msg
string
ini entries:

[callback_diy]
runner_on_no_hosts_msg = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ON_NO_HOSTS_MSG
var: ansible_callback_diy_runner_on_no_hosts_msg
Output to be used for callback runner_on_no_hosts.
runner_on_no_hosts_msg_color
string
ini entries:

[callback_diy]
runner_on_no_hosts_msg_color = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ON_NO_HOSTS_MSG_COLOR
var: ansible_callback_diy_runner_on_no_hosts_msg_color
Output color to be used for runner_on_no_hosts_msg.
Template should render a valid color value.
runner_on_ok_msg
string
ini entries:

[callback_diy]
runner_on_ok_msg = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ON_OK_MSG
var: ansible_callback_diy_runner_on_ok_msg
Output to be used for callback runner_on_ok.
runner_on_ok_msg_color
string
ini entries:

[callback_diy]
runner_on_ok_msg_color = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ON_OK_MSG_COLOR
var: ansible_callback_diy_runner_on_ok_msg_color
Output color to be used for runner_on_ok_msg.
Template should render a valid color value.
runner_on_skipped_msg
string
ini entries:

[callback_diy]
runner_on_skipped_msg = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ON_SKIPPED_MSG
var: ansible_callback_diy_runner_on_skipped_msg
Output to be used for callback runner_on_skipped.
runner_on_skipped_msg_color
string
ini entries:

[callback_diy]
runner_on_skipped_msg_color = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ON_SKIPPED_MSG_COLOR
var: ansible_callback_diy_runner_on_skipped_msg_color
Output color to be used for runner_on_skipped_msg.
Template should render a valid color value.
runner_on_start_msg
string
ini entries:

[callback_diy]
runner_on_start_msg = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ON_START_MSG
var: ansible_callback_diy_runner_on_start_msg
Output to be used for callback runner_on_start.
runner_on_start_msg_color
string
ini entries:

[callback_diy]
runner_on_start_msg_color = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ON_START_MSG_COLOR
var: ansible_callback_diy_runner_on_start_msg_color
Output color to be used for runner_on_start_msg.
Template should render a valid color value.
runner_on_unreachable_msg
string
ini entries:

[callback_diy]
runner_on_unreachable_msg = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ON_UNREACHABLE_MSG
var: ansible_callback_diy_runner_on_unreachable_msg
Output to be used for callback runner_on_unreachable.
runner_on_unreachable_msg_color
string
ini entries:

[callback_diy]
runner_on_unreachable_msg_color = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_ON_UNREACHABLE_MSG_COLOR
var: ansible_callback_diy_runner_on_unreachable_msg_color
Output color to be used for runner_on_unreachable_msg.
Template should render a valid color value.
runner_retry_msg
string
ini entries:

[callback_diy]
runner_retry_msg = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_RETRY_MSG
var: ansible_callback_diy_runner_retry_msg
Output to be used for callback runner_retry.
runner_retry_msg_color
string
ini entries:

[callback_diy]
runner_retry_msg_color = None

env:ANSIBLE_CALLBACK_DIY_RUNNER_RETRY_MSG_COLOR
var: ansible_callback_diy_runner_retry_msg_color
Output color to be used for runner_retry_msg.
Template should render a valid color value.
show_custom_stats
boolean
    Choices:
  • no
  • yes
ini entries:

[defaults]
show_custom_stats = no

env:ANSIBLE_SHOW_CUSTOM_STATS
This adds the custom stats set via the set_stats plugin to the play recap
show_per_host_start
boolean
added in 2.9 of ansible.builtin
    Choices:
  • no
  • yes
ini entries:

[defaults]
show_per_host_start = no

env:ANSIBLE_SHOW_PER_HOST_START
This adds output that shows when a task is started to execute for each host
show_task_path_on_failure
boolean
added in 2.11 of ansible.builtin
    Choices:
  • no
  • yes
ini entries:

[defaults]
show_task_path_on_failure = no

env:ANSIBLE_SHOW_TASK_PATH_ON_FAILURE
When a task fails, display the path to the file containing the failed task and the line number. This information is displayed automatically for every task when running with -vv or greater verbosity.

Notes

Note

  • Uses the default callback plugin output when a custom callback message(msg) is not provided.
  • Makes the callback event data available via the ansible_callback_diy dictionary, which can be used in the templating context for the options. The dictionary is only available in the templating context for the options. It is not a variable that is available via the other various execution contexts, such as playbook, play, task etc.
  • Options being set by their respective variable input can only be set using the variable if the variable was set in a context that is available to the respective callback. Use the ansible_callback_diy dictionary to see what is available to a callback. Additionally, ansible_callback_diy.top_level_var_names will output the top level variable names available to the callback.
  • Each option value is rendered as a template before being evaluated. This allows for the dynamic usage of an option. For example, "{{ 'yellow' if ansible_callback_diy.result.is_changed else 'bright green' }}"
  • Condition for all msg options: if value is None or omit, then the option is not being used. Effect: use of the default callback plugin for output
  • Condition for all msg options: if value is not None and not omit and length is not greater than 0, then the option is being used without output. Effect: suppress output
  • Condition for all msg options: if value is not None and not omit and length is greater than 0, then the option is being used with output. Effect: render value as template and output
  • Valid color values: black, bright gray, blue, white, green, bright blue, cyan, bright green, red, bright cyan, purple, bright red, yellow, bright purple, dark gray, bright yellow, magenta, bright magenta, normal

See Also

See also

default – default Ansible screen output

The official documentation on the default callback plugin.

Examples

ansible.cfg: >
  # Enable plugin
  [defaults]
  stdout_callback=community.general.diy

  [callback_diy]
  # Output when playbook starts
  playbook_on_start_msg="DIY output(via ansible.cfg): playbook example: {{ ansible_callback_diy.playbook.file_name }}"
  playbook_on_start_msg_color=yellow

  # Comment out to allow default plugin output
  # playbook_on_play_start_msg="PLAY: starting play {{ ansible_callback_diy.play.name }}"

  # Accept on_skipped_msg or ansible_callback_diy_runner_on_skipped_msg as input vars
  # If neither are supplied, omit the option
  runner_on_skipped_msg="{{ on_skipped_msg | default(ansible_callback_diy_runner_on_skipped_msg) | default(omit) }}"

  # Newline after every callback
  # on_any_msg='{{ " " | join("\n") }}'

playbook.yml: >
  ---
  - name: "Default plugin output: play example"
    hosts: localhost
    gather_facts: no
    tasks:
      - name:  Default plugin output
        ansible.builtin.debug:
          msg: default plugin output

  - name: Override from play vars
    hosts: localhost
    gather_facts: no
    vars:
      ansible_connection: local
      green: "\e[0m\e[38;5;82m"
      yellow: "\e[0m\e[38;5;11m"
      bright_purple: "\e[0m\e[38;5;105m"
      cyan: "\e[0m\e[38;5;51m"
      green_bg_black_fg: "\e[0m\e[48;5;40m\e[38;5;232m"
      yellow_bg_black_fg: "\e[0m\e[48;5;226m\e[38;5;232m"
      purple_bg_white_fg: "\e[0m\e[48;5;57m\e[38;5;255m"
      cyan_bg_black_fg: "\e[0m\e[48;5;87m\e[38;5;232m"
      magenta: "\e[38;5;198m"
      white: "\e[0m\e[38;5;255m"
      ansible_callback_diy_playbook_on_play_start_msg: "\n{{green}}DIY output(via play vars): play example: {{magenta}}{{ansible_callback_diy.play.name}}\n\n"
      ansible_callback_diy_playbook_on_task_start_msg: "DIY output(via play vars): task example: {{ ansible_callback_diy.task.name }}"
      ansible_callback_diy_playbook_on_task_start_msg_color: cyan
      ansible_callback_diy_playbook_on_stats_msg: |+2
                CUSTOM STATS
        ==============================
        {% for key in ansible_callback_diy.stats | sort %}
        {% if ansible_callback_diy.stats[key] %}
        {% if key == 'ok' %}
        {% set color_one = lookup('vars','green_bg_black_fg') %}
        {% set prefix = '      ' %}
        {% set suffix = '     ' %}
        {% set color_two = lookup('vars','green') %}
        {% elif key == 'changed' %}
        {% set color_one = lookup('vars','yellow_bg_black_fg') %}
        {% set prefix = '   ' %}
        {% set suffix = '   ' %}
        {% set color_two = lookup('vars','yellow') %}
        {% elif key == 'processed' %}
        {% set color_one = lookup('vars','purple_bg_white_fg') %}
        {% set prefix = '  ' %}
        {% set suffix = '  ' %}
        {% set color_two = lookup('vars','bright_purple') %}
        {% elif key == 'skipped' %}
        {% set color_one = lookup('vars','cyan_bg_black_fg') %}
        {% set prefix = '   ' %}
        {% set suffix = '   ' %}
        {% set color_two = lookup('vars','cyan') %}
        {% else %}
        {% set color_one = "" %}
        {% set prefix = "" %}
        {% set suffix = "" %}
        {% set color_two = "" %}
        {% endif %}
        {{ color_one }}{{ "%s%s%s" | format(prefix,key,suffix) }}{{ color_two }}: {{ ansible_callback_diy.stats[key] | to_nice_yaml }}
        {% endif %}
        {% endfor %}

    tasks:
      - name: Custom banner with default plugin result output
        ansible.builtin.debug:
          msg: "default plugin output: result example"

      - name: Override from task vars
        ansible.builtin.debug:
          msg: "example {{ two }}"
        changed_when: true
        vars:
          white_fg_red_bg: "\e[0m\e[48;5;1m"
          two: "{{ white_fg_red_bg }}    2    "
          ansible_callback_diy_playbook_on_task_start_msg: "\nDIY output(via task vars): task example: {{ ansible_callback_diy.task.name }}"
          ansible_callback_diy_playbook_on_task_start_msg_color: bright magenta
          ansible_callback_diy_runner_on_ok_msg: "DIY output(via task vars): result example: \n{{ ansible_callback_diy.result.output.msg }}\n"
          ansible_callback_diy_runner_on_ok_msg_color: "{{ 'yellow' if ansible_callback_diy.result.is_changed else 'bright green' }}"

      - name: Suppress output
        ansible.builtin.debug:
          msg: i should not be displayed
        vars:
          ansible_callback_diy_playbook_on_task_start_msg: ""
          ansible_callback_diy_runner_on_ok_msg: ""

      - name: Using alias vars (see ansible.cfg)
        ansible.builtin.debug:
          msg:
        when: False
        vars:
          ansible_callback_diy_playbook_on_task_start_msg: ""
          on_skipped_msg: "DIY output(via task vars): skipped example:\n\e[0m\e[38;5;4m\u25b6\u25b6 {{ ansible_callback_diy.result.task.name }}\n"
          on_skipped_msg_color: white

      - name: Just stdout
        ansible.builtin.command: echo some stdout
        vars:
          ansible_callback_diy_playbook_on_task_start_msg: "\n"
          ansible_callback_diy_runner_on_ok_msg: "{{ ansible_callback_diy.result.output.stdout }}\n"

      - name: Multiline output
        ansible.builtin.debug:
          msg: "{{ multiline }}"
        vars:
          ansible_callback_diy_playbook_on_task_start_msg: "\nDIY output(via task vars): task example: {{ ansible_callback_diy.task.name }}"
          multiline: "line\nline\nline"
          ansible_callback_diy_runner_on_ok_msg: |+2
            some
            {{ ansible_callback_diy.result.output.msg }}
            output

          ansible_callback_diy_playbook_on_task_start_msg_color: bright blue

      - name: Indentation
        ansible.builtin.debug:
          msg: "{{ item.msg }}"
        with_items:
          - { indent: 1, msg: one., color: red }
          - { indent: 2, msg: two.., color: yellow }
          - { indent: 3, msg: three..., color: bright yellow }
        vars:
          ansible_callback_diy_runner_item_on_ok_msg: "{{ ansible_callback_diy.result.output.msg | indent(item.indent, True) }}"
          ansible_callback_diy_runner_item_on_ok_msg_color: "{{ item.color }}"
          ansible_callback_diy_runner_on_ok_msg: "GO!!!"
          ansible_callback_diy_runner_on_ok_msg_color: bright green

      - name: Using lookup and template as file
        ansible.builtin.shell: "echo {% raw %}'output from {{ file_name }}'{% endraw %} > {{ file_name }}"
        vars:
          ansible_callback_diy_playbook_on_task_start_msg: "\nDIY output(via task vars): task example: {{ ansible_callback_diy.task.name }}"
          file_name: diy_file_template_example
          ansible_callback_diy_runner_on_ok_msg: "{{ lookup('template', file_name) }}"

      - name: 'Look at top level vars available to the "runner_on_ok" callback'
        ansible.builtin.debug:
          msg: ''
        vars:
          ansible_callback_diy_playbook_on_task_start_msg: "\nDIY output(via task vars): task example: {{ ansible_callback_diy.task.name }}"
          ansible_callback_diy_runner_on_ok_msg: |+2
            {% for var in (ansible_callback_diy.top_level_var_names|reject('match','vars|ansible_callback_diy.*')) | sort %}
            {{ green }}{{ var }}:
              {{ white }}{{ lookup('vars', var) }}

            {% endfor %}
          ansible_callback_diy_runner_on_ok_msg_color: white

      - name: 'Look at event data available to the "runner_on_ok" callback'
        ansible.builtin.debug:
          msg: ''
        vars:
          ansible_callback_diy_playbook_on_task_start_msg: "\nDIY output(via task vars): task example: {{ ansible_callback_diy.task.name }}"
          ansible_callback_diy_runner_on_ok_msg: |+2
            {% for key in ansible_callback_diy | sort %}
            {{ green }}{{ key }}:
              {{ white }}{{ ansible_callback_diy[key] }}

            {% endfor %}

Authors

  • Trevor Highfill (@theque5t)

© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/community/general/diy_callback.html