Commit d1259285 authored by Evangelos Foutras's avatar Evangelos Foutras 🐱
Browse files

Merge branch 'optimize-hcloud_inventory' into 'master'

hcloud_inventory: Optimize --list to avoid --host calls

See merge request archlinux/infrastructure!459
parents b3f94001 452090f6
......@@ -19,12 +19,7 @@ def parse_args():
return parser.parse_args()
def list_running_hosts(client):
return [ for server in client.servers.get_all()]
def get_host_details(client, host):
server = client.servers.get_by_name(host)
def get_host_details(server):
return {'ansible_host': server.public_net.ipv4.ip,
'ansible_port': 22,
'ansible_user': "root"}
......@@ -34,13 +29,14 @@ def main():
args = parse_args()
loaded = load_vault('misc/vault_hetzner.yml')
client = Client(token=loaded["hetzner_cloud_api_key"])
servers = client.servers.get_all()
hostvars = { get_host_details(server) for server in servers}
if args.list:
hosts = list_running_hosts(client=client)
json.dump({'hcloud': hosts}, sys.stdout)
hosts = [ for server in servers]
json.dump({'hcloud': hosts, '_meta': {'hostvars': hostvars}}, sys.stdout)
details = get_host_details(client,
json.dump(details, sys.stdout)
json.dump(hostvars[], sys.stdout)
if __name__ == '__main__':
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment