1
0
Fork 0
mirror of https://github.com/DO1JLR/ansible_linux_desktop_setup.git synced 2024-09-14 19:54:51 +02:00

successful return empty inv

This commit is contained in:
L3D 2022-06-18 13:16:59 +02:00
parent b44d717ed9
commit 293cff2649

View file

@ -5,6 +5,7 @@ Create a dynamic inventory for this ansible playbook
""" """
import socket import socket
import sys import sys
import json
# create a dict to match hostnames to enviroments # create a dict to match hostnames to enviroments
env_dict = { env_dict = {
@ -27,8 +28,16 @@ def env(domain):
for key, values in env_dict.items(): for key, values in env_dict.items():
if domain in values: if domain in values:
return key return key
sys.exit('{"group": { "hosts": ["example.com"], "vars": {} }, "_meta": { "foo": "bar" }}') print(json.dumps(empty_host_list(), sort_keys=True, indent=2))
sys.exit()
def empty_host_list():
"""
return empty host list
"""
comment = "No valid host found. returning empty host list!"
return json.loads('{"_meta": {"comment": "' + comment +
'", "hostvars": {}}, "instances": {"hosts": []}}')
def main(): def main():
""" """
@ -41,11 +50,13 @@ def main():
group = env(host) group = env(host)
print(host + group) print(host + group)
#{ #{
# "group": # "_meta": {
# { "hosts": ["127.0.0.1", "::1"], "vars": {} }, # "hostvars": { }
# "_meta": # },
# { "hostvars": { "192.168.28.71": { "host_specific_var": "bar" }, #
# "192.168.28.72": { "host_specific_var": "foo" }} } # "instances": {
# "hosts": ["10.66.70.33"]
# }
# } # }
main() main()