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
├── 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