# another python API question

**URL:** <https://forum.ansible.com/t/another-python-api-question/36184>\
**Category:** Ansible Project\
**Created:** [January 6, 2022, 10:30pm UTC](https://forum.ansible.com/t/another-python-api-question/36184 "2022-01-06T22:30:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [January 6, 2022, 10:30pm UTC](https://forum.ansible.com/t/another-python-api-question/36184/1 "2022-01-06T22:30:11Z")

</div>

Hii

Triggered by a previous poster, I sometimes need to access specific host vars from python but don’t know how.  
An example deployment would consist of a directory like this:

(venv) dvs@GA0267 deploy1$ tree

**.**

├── ansible.cfg

├── inventory.ini

├── **playbooks**

│ ├── borg.yml

│ ├── cache.yml

│ ├── esxi.yml

│ ├── **group\_vars**

│ │ ├── **all**

│ │ │ ├── ca\_certs.yml

│ │ │ ├── main.yml

│ │ │ ├── pubkeys.yml

│ │ │ └── vaulted\_vars.yml

│ │ ├── **piholes**

│ │ │ └── vault.yml

│ │ └── **villas**

│ │ ├── main.yml

│ │ └── vaulted\_vars.yml

│ ├── **host\_vars**

│ │ └── **villa**

│ │ ├── main.yml

│ │ └── vault.yml

│ ├── nagios.yml

│ ├── pihole.yml

│ ├── sshd.yml

│ └── villa.yml

├── [requirements.in](http://requirements.in)

├── requirements.txt

└── **vault**

When I want to access a specific variable, I use shell kludges like:

(venv) dvs@GA0267 deploy1$ ANSIBLE\_STDOUT\_CALLBACK=json ansible --playbook-dir playbooks pihole-4a -m debug -a var=smtp\_relay\_password | sed ‘1s/^.\*$/{/’ | jq -r .smtp\_relay\_password  
hackme

I tried with Templar but couldn’t glue it together.

What would be the simplest way to fetch a variable like this from a python script?

thx
