ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
821 stars 1.52k forks source link

Warning for undefined variables if `ansible_callback_diy.task.name` is used with `ansible_callback_diy_playbook_on_task_start_msg` #5617

Open tina-junold opened 1 year ago

tina-junold commented 1 year ago

Summary

I try to set ansible_callback_diy_playbook_on_task_start_msg to ansible_callback_diy.task.name witch will lead to an Callback warning

Issue Type

Bug Report

Component Name

community.general.diy callback

Ansible Version

ansible [core 2.14.0]
  config file = /home/tina/some-project/ansible.cfg
  configured module search path = ['/home/tina/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/tina/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/tina/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/tina/.local/bin/ansible
  python version = 3.10.7 (main, Nov  2 2022, 18:49:29) [GCC 12.2.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Community.general Version

# /home/tina/.local/lib/python3.10/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 5.6.0  

# /home/tina/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 6.0.1  

Configuration

CONFIG_FILE() = /home/tina/some-project/ansible.cfg
DEFAULT_LOAD_CALLBACK_PLUGINS(/home/tina/some-project/ansible.cfg) = True
DEFAULT_STDOUT_CALLBACK(/home/tina/some-project/ansible.cfg) = community.general.diy
INTERPRETER_PYTHON(/home/tina/some-project/ansible.cfg) = {{ ansible_playbook_python }}
INVENTORY_UNPARSED_WARNING(/home/tina/some-project/ansible.cfg) = False
LOCALHOST_WARNING(/home/tina/some-project/ansible.cfg) = False

OS / Environment

Distributor ID: Ubuntu Description: Ubuntu 22.10 Release: 22.10 Codename: kinetic

Steps to Reproduce

# code: language=ansible
---
- name: Development
  hosts: localhost
  gather_facts: false
  remote_user: user
  vars:
    ansible_callback_diy_playbook_on_task_start_msg: "{{ ansible_callback_diy.task.name }}"
    ansible_callback_diy_playbook_on_task_start_msg_color: white

    container:
      enabled: false
  tasks:
    - name: Set task host to 'localhost'
      ansible.builtin.set_fact:
        task_host: localhost
      when: not container.enabled

    - name: Set 'base_dir'
      ansible.builtin.set_fact:
        base_dir: "{{ container.enabled | ternary('/home/user/project/', '') }}"

    - name: List files
      delegate_to: "{{ task_host }}"
      ansible.builtin.command:
        chdir: "{{ base_dir }}"
        cmd: ls -lha

Expected Results

I don't expect any warnings

Actual Results

PLAY [Development] ********************************************************************************************************************************************************************************************************************************************************************************************************
Set task host to 'localhost'
ok: [localhost]
Set 'base_dir'
ok: [localhost]
[WARNING]: Failure using method (v2_playbook_on_task_start) in callback plugin (<ansible_collections.community.general.plugins.callback.diy.CallbackModule object at 0x7fe670478a60>): {'playbook': {'entries': [Development], 'file_name': 'test.yml', 'basedir': '/home/tina/some-project'}, 'play':
{'any_errors_fatal': False, 'become': False, 'become_flags': None, 'become_method': 'sudo', 'become_user': None, 'check_mode': False, 'collections': [], 'connection': 'ssh', 'debugger': None, 'diff': False, 'environment': None, 'fact_path': None, 'finalized': True, 'force_handlers': False, 'gather_facts': False,
'gather_subset': None, 'gather_timeout': None, 'handlers': [], 'hosts': ['localhost'], 'ignore_errors': None, 'ignore_unreachable': None, 'included_conditional': None, 'included_path': None, 'max_fail_percentage': None, 'module_defaults': None, 'name': 'Development', 'no_log': None, 'only_tags': {'all'}, 'order':
None, 'port': None, 'post_tasks': [], 'pre_tasks': [], 'remote_user': 'user', 'removed_hosts': [], 'roles': [], 'run_once': None, 'serial': [], 'skip_tags': set(), 'squashed': False, 'strategy': 'linear', 'tags': [], 'tasks': [BLOCK(uuid=eb84ffe2-d0ac-284f-1a18-000000000002)(id=140627710349408)(parent=None)],
'uuid': 'eb84ffe2-d0ac-284f-1a18-000000000001', 'validated': True, 'vars_files': [], 'vars_prompt': []}, 'task': {'action': 'ansible.builtin.command', 'any_errors_fatal': False, 'args': {'chdir': '{{ base_dir }}', '_raw_params': 'ls -lha'}, 'async': 0, 'async_val': 0, 'become': False, 'become_flags': None,
'become_method': 'sudo', 'become_user': None, 'changed_when': [], 'check_mode': False, 'collections': [], 'connection': 'ssh', 'debugger': None, 'delay': 5, 'delegate_facts': None, 'delegate_to': '{{ task_host }}', 'diff': False, 'environment': [], 'failed_when': [], 'finalized': False, 'ignore_errors': None,
'ignore_unreachable': None, 'loop': None, 'loop_control': <ansible.playbook.loop_control.LoopControl object at 0x7fe6702d1d20>, 'loop_with': None, 'module_defaults': [], 'name': 'List files', 'no_log': None, 'notify': None, 'parent':
BLOCK(uuid=eb84ffe2-d0ac-284f-1a18-000000000002)(id=140627710349408)(parent=None), 'poll': 15, 'port': None, 'register': None, 'remote_user': 'user', 'retries': 3, 'role': None, 'run_once': None, 'squashed': False, 'tags': [], 'untagged': frozenset({'untagged'}), 'until': [], 'uuid':
'eb84ffe2-d0ac-284f-1a18-000000000005', 'validated': True, 'when': []}, 'top_level_var_names': ['ansible_callback_diy_playbook_on_task_start_msg', 'ansible_callback_diy_playbook_on_task_start_msg_color', 'container', 'playbook_dir', 'ansible_playbook_python', 'ansible_config_file', 'ansible_role_names',
'ansible_play_role_names', 'ansible_dependent_role_names', 'role_names', 'ansible_play_name', 'groups', 'ansible_play_hosts_all', 'ansible_play_hosts', 'ansible_play_batch', 'play_hosts', 'omit', 'ansible_version', 'ansible_check_mode', 'ansible_diff_mode', 'ansible_forks', 'ansible_inventory_sources',
'ansible_skip_tags', 'ansible_run_tags', 'ansible_verbosity', 'hostvars', 'environment', 'vars', 'ansible_callback_diy']}: 'base_dir' is undefined. 'base_dir' is undefined. {'playbook': {'entries': [Development], 'file_name': 'test.yml', 'basedir': '/home/tina/some-project'}, 'play':
{'any_errors_fatal': False, 'become': False, 'become_flags': None, 'become_method': 'sudo', 'become_user': None, 'check_mode': False, 'collections': [], 'connection': 'ssh', 'debugger': None, 'diff': False, 'environment': None, 'fact_path': None, 'finalized': True, 'force_handlers': False, 'gather_facts': False,
'gather_subset': None, 'gather_timeout': None, 'handlers': [], 'hosts': ['localhost'], 'ignore_errors': None, 'ignore_unreachable': None, 'included_conditional': None, 'included_path': None, 'max_fail_percentage': None, 'module_defaults': None, 'name': 'Development', 'no_log': None, 'only_tags': {'all'}, 'order':
None, 'port': None, 'post_tasks': [], 'pre_tasks': [], 'remote_user': 'user', 'removed_hosts': [], 'roles': [], 'run_once': None, 'serial': [], 'skip_tags': set(), 'squashed': False, 'strategy': 'linear', 'tags': [], 'tasks': [BLOCK(uuid=eb84ffe2-d0ac-284f-1a18-000000000002)(id=140627710349408)(parent=None)],
'uuid': 'eb84ffe2-d0ac-284f-1a18-000000000001', 'validated': True, 'vars_files': [], 'vars_prompt': []}, 'task': {'action': 'ansible.builtin.command', 'any_errors_fatal': False, 'args': {'chdir': '{{ base_dir }}', '_raw_params': 'ls -lha'}, 'async': 0, 'async_val': 0, 'become': False, 'become_flags': None,
'become_method': 'sudo', 'become_user': None, 'changed_when': [], 'check_mode': False, 'collections': [], 'connection': 'ssh', 'debugger': None, 'delay': 5, 'delegate_facts': None, 'delegate_to': '{{ task_host }}', 'diff': False, 'environment': [], 'failed_when': [], 'finalized': False, 'ignore_errors': None,
'ignore_unreachable': None, 'loop': None, 'loop_control': <ansible.playbook.loop_control.LoopControl object at 0x7fe6702d1d20>, 'loop_with': None, 'module_defaults': [], 'name': 'List files', 'no_log': None, 'notify': None, 'parent':
BLOCK(uuid=eb84ffe2-d0ac-284f-1a18-000000000002)(id=140627710349408)(parent=None), 'poll': 15, 'port': None, 'register': None, 'remote_user': 'user', 'retries': 3, 'role': None, 'run_once': None, 'squashed': False, 'tags': [], 'untagged': frozenset({'untagged'}), 'until': [], 'uuid':
'eb84ffe2-d0ac-284f-1a18-000000000005', 'validated': True, 'when': []}, 'top_level_var_names': ['ansible_callback_diy_playbook_on_task_start_msg', 'ansible_callback_diy_playbook_on_task_start_msg_color', 'container', 'playbook_dir', 'ansible_playbook_python', 'ansible_config_file', 'ansible_role_names',
'ansible_play_role_names', 'ansible_dependent_role_names', 'role_names', 'ansible_play_name', 'groups', 'ansible_play_hosts_all', 'ansible_play_hosts', 'ansible_play_batch', 'play_hosts', 'omit', 'ansible_version', 'ansible_check_mode', 'ansible_diff_mode', 'ansible_forks', 'ansible_inventory_sources',
'ansible_skip_tags', 'ansible_run_tags', 'ansible_verbosity', 'hostvars', 'environment', 'vars', 'ansible_callback_diy']}: 'base_dir' is undefined. 'base_dir' is undefined

TASK [Set 'base_dir'] *****************************************************************************************************************************************************************************************************************************************************************************************************
changed: [localhost]

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

Code of Conduct

ansibullbot commented 1 year ago

Files identified in the description: None

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

tina-junold commented 1 year ago

!component =community.general.diy callback

ansibullbot commented 1 year ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 1 year ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

tina-junold commented 1 year ago

!component =plugins/callback/diy.py

ansibullbot commented 1 year ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 1 year ago

cc @theque5t click here for bot help