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 sys
import json
# create a dict to match hostnames to enviroments
env_dict = {
@ -27,8 +28,16 @@ def env(domain):
for key, values in env_dict.items():
if domain in values:
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():
"""
@ -40,12 +49,14 @@ def main():
host = fqdn()
group = env(host)
print(host + group)
# {
# "group":
# { "hosts": ["127.0.0.1", "::1"], "vars": {} },
# "_meta":
# { "hostvars": { "192.168.28.71": { "host_specific_var": "bar" },
# "192.168.28.72": { "host_specific_var": "foo" }} }
#{
# "_meta": {
# "hostvars": { }
# },
#
# "instances": {
# "hosts": ["10.66.70.33"]
# }
# }
main()