From 0cf4e9f60e3b1fa994e7dd707c1052231ca2dcaf Mon Sep 17 00:00:00 2001 From: Wolfgang Medina-Erhardt Date: Wed, 27 Nov 2024 09:30:07 +0100 Subject: [PATCH] Remove inventory files --- inventory.ini | 30 ---------------------------- inventory.py | 54 --------------------------------------------------- 2 files changed, 84 deletions(-) delete mode 100644 inventory.ini delete mode 100755 inventory.py diff --git a/inventory.ini b/inventory.ini deleted file mode 100644 index c6155f4..0000000 --- a/inventory.ini +++ /dev/null @@ -1,30 +0,0 @@ -[app_prd] -vpro0000.proserver.punkt.de ansible_user=vpro0000 - -[app_stg] -vpro0000.proserver.punkt.de ansible_user=vpro0000 - -[app] -[app:children] -app_stg -app_prd - -[production] -[production:children] -app_prd - -[staging] -[staging:children] -app_stg - -[mailhog] -[mailhog:children] -app_stg - -[secrets] -[secrets:children] -app - -[mariadb] -[mariadb:children] -app diff --git a/inventory.py b/inventory.py deleted file mode 100755 index 7a859c1..0000000 --- a/inventory.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python3 -import json -import yaml -import requests -from typing import List - - -class Inventory: - inventory_url = None - vars = None - - def __init__(self, inventory_url='https://inventory.punkt.app'): - self.inventory_url = inventory_url - self._load_vars() - self._load_public_keys() - - def _load_vars(self) -> None: - with requests.get(f'{self.inventory_url}/defaults/main.yaml', stream=True, timeout=30) as response: - self.vars = yaml.safe_load(response.content) - - def _load_public_keys(self) -> None: - for user, user_info in self.vars['punktde']['people'].items(): - user_info['public_keys'] = self._get_public_keys(user, user_info['email']) - - def _get_public_keys(self, user: str, email: str) -> List: - response = requests.get(f'{self.inventory_url}/files/public_keys/{user}.pub', timeout=30) - if response.status_code != 200: - return [] - - public_keys = [] - for public_key in response.content.decode().splitlines(): - public_key = public_key.strip() - if not public_key or public_key.startswith('#'): - continue - public_key = public_key.split(' ', 2) - public_key = f'{public_key[0]} {public_key[1]} {email}' - public_keys.append(public_key) - break - - return public_keys - - def inventory(self): - return { - 'all': { - 'vars': self.vars, - } - } - - def __str__(self) -> str: - return json.dumps(self.inventory()) - - -if __name__ == '__main__': - print(str(Inventory()))