# Accessing top-level playbook vars from a custom callback plugin

**URL:** <https://forum.ansible.com/t/accessing-top-level-playbook-vars-from-a-custom-callback-plugin/8590>\
**Category:** Get Help\
**Tags:** playbook, ansible-core\
**Created:** [September 18, 2024, 11:56am UTC](https://forum.ansible.com/t/accessing-top-level-playbook-vars-from-a-custom-callback-plugin/8590 "2024-09-18T11:56:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorge\_Rua](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jorge_rua/32/4787_2.png) [@Jorge\_Rua](https://forum.ansible.com/u/Jorge_Rua)\
**Post date:** [September 18, 2024, 11:56am UTC](https://forum.ansible.com/t/accessing-top-level-playbook-vars-from-a-custom-callback-plugin/8590/1 "2024-09-18T11:56:17Z")

</div>

Hello everyone,

I’m creating a custom stdout callback plugin that allow me to run infrastructure tests and create a report accordingly. Here’s how it looks:

```auto
+-----------+---------------------------+------------------+--------------------------------------+----------+
| Host | Task | Expected Value | Obtained Value | Status |
+===========+===========================+==================+======================================+==========+
| localhost | Test disk space | 100GB | 100GB | OK |
+-----------+---------------------------+------------------+--------------------------------------+----------+
| localhost | Test network connectivity | | PING google.com (74.125.206.102) ... | FAILED |
+-----------+---------------------------+------------------+--------------------------------------+----------+

+-----------+---------------+----------------+----------------+-------------------+
| Host | Total Tests | Tests Passed | Tests Failed | Pass Percentage |
+===========+===============+================+================+===================+
| localhost | 2 | 1 | 1 | 50.00% |
+-----------+---------------+----------------+----------------+-------------------+

```

However I am unable to access top-level playbook variables from the stdout callback, and thus I am only able to pass literals as `expected_output` to each task. Here’s the playbook that generated the above output so you can have a more clear understanding on what’s going on:

```auto
---
- name: Linux test
  hosts: localhost
  gather_facts: True
  vars:
    disk_space_threshold: "100GB"
    network_status: "True"
    generate_html_report: true

  tasks:
    - name: Set facts from playbook vars
      set_fact:
        expected_disk_space: "{{ disk_space_threshold }}"
        expected_connectivity: "{{ network_status }}"

    - name: Test disk space
      ansible.builtin.command: "echo 100GB"
      register: disk_output
      vars:
        # This works fine
        expected_output: "100GB"
        # This doesn't work either via top-level pb var or set_fact
        # expected_output: "{{ expected_disk_space }}"

    - name: Test network connectivity
      ansible.builtin.shell: "ping -c 1 google.com"
      register: network_output
      vars:
        expected_output: "{{ expected_connectivity }}"

```

Any thoughts or ideas?

## Thanks,

Jorge Rua

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [September 19, 2024, 5:37pm UTC](https://forum.ansible.com/t/accessing-top-level-playbook-vars-from-a-custom-callback-plugin/8590/2 "2024-09-19T17:37:52Z")

</div>

It would really help to see how you are accessing variables in your custom callback.
