How To Set Vars Into Ansible Inventory?
In playbook I'm using variable {{excluded_service}}. I want to run ansible playbook from python and provide this variable. And I can't use external inventory script to provide this
Solution 1:
Specify the vars in a host_vars file?
E.g. create a YAML file named /etc/ansible/host_vars/localhost
with the vars you wanna put there.
I don't know, yet, how to specify it in Python code itself.
--- update ---
After a quick look the code, I don't think ansible supports specifying host variables when you specify hosts via host_list
parameter. Hacks I can think of (if you must do this in python
code) are:
- [mis]use extra_vars parameter.
- Write an inventory file (YAML or executable that just prints required JSON) from your python code and pass it's path as parameter
inventory
.
HTH
Post a Comment for "How To Set Vars Into Ansible Inventory?"