From de8c9f3fc690e11ad212e3da16496b7bbed79e1d Mon Sep 17 00:00:00 2001 From: Olivier Date: Tue, 8 Oct 2024 12:19:49 +0200 Subject: [PATCH] =?UTF-8?q?Pr=C3=A9paration=20ansible-pull?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libreticmenu/AnsibleActions.py | 12 +++++------- libreticmenu/libreticmenu.py | 33 +++++++++++---------------------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/libreticmenu/AnsibleActions.py b/libreticmenu/AnsibleActions.py index 4f31685..93d8977 100644 --- a/libreticmenu/AnsibleActions.py +++ b/libreticmenu/AnsibleActions.py @@ -1,9 +1,7 @@ import subprocess -import os -import glob + +def runAnsiblePlaybook(config, key): + subprocess.check_call(['ansible-playbook', config['ansiblemenu'][key]['playbook']], cwd=config['base_path']) -def runAnsiblePlaybook(config, key, branch): - subprocess.run(['ansible-playbook', config['ansiblemenu'][key]['playbook']], check=True, cwd=config['base_path']) - -def pullAnsiblePlaybook(config, key, branch): - subprocess.run(['ansible-pull', config['ansiblemenu'][key]['playbook']], check=True, cwd=config['base_path']) +def pullAnsiblePlaybook(url, playbook): + subprocess.check_call(['ansible-pull', '-U', url, playbook]) diff --git a/libreticmenu/libreticmenu.py b/libreticmenu/libreticmenu.py index aed78c9..54a7b12 100644 --- a/libreticmenu/libreticmenu.py +++ b/libreticmenu/libreticmenu.py @@ -70,39 +70,28 @@ def hostnameChoice(): ### Menu du choix playbook externe def extPlaybookChoice(): url = inquirer.text( - message = "Renseigner l'url du projet git (exemple : https://adresse-serveur-git/projet.git)", + message = "Renseigner l'url du projet git (exemple : https://adresse-serveur-git/projet.git) :", validate = lambda url : len(url) > 0 and (url.startswith("http://") or url.startswith("https://")) and - url.endswith(".git") + url.endswith(".git"), + invalid_message = "Une url de projet git doit commencer par http(s):// et se terminer par .git" ).execute() playbook = inquirer.text( - message = "Renseigner le nom du playbook", + message = "Renseigner le nom du playbook :", validate = lambda playbook : len(playbook) > 0 and - (playbook.endswith(".yaml") or playbook.endswith(".yml")) + (playbook.endswith(".yaml") or playbook.endswith(".yml")), + invalid_message = "Un nom de playbook doit se terminer par .yml ou .yaml" ).execute() - branch = inquirer.text( - message = "Branche du projet (laisser vide pour branche par défaut)", - ).execute() - - username = inquirer.text( - message = "Identifiant de connexion (laisser vide si projet public)", - ).execute() - - if username != "": - password = inquirer.secret( - message = "Mot de passe de connexion", - ).execute() - proceed = inquirer.confirm( - message ="Définir {} comme nom de machine ?".format(project), + message ="Confirmer l'exécution du playbook {} du projet {} ?".format(playbook, url), confirm_letter = "o", default=False).execute() if proceed: - print("Confirmation") + AnsibleActions.pullAnsiblePlaybook(url, playbook) else: print("Annulation") @@ -149,11 +138,11 @@ def main(): for entry in config['ansiblemenu']: if not config['ansiblemenu'][entry].get('menu_hidden', False): menu_main = menu_main | { - config['ansiblemenu'][entry]['menu_title']: lambda e=entry: AnsibleActions.runAnsiblePlaybook(config, e, currentBranch) + config['ansiblemenu'][entry]['menu_title']: lambda e=entry: AnsibleActions.runAnsiblePlaybook(config, e) } menu_main = menu_main | { - "Exécuter un playbook d'un projet externe": extPlaybookChoice, + "Exécuter un playbook d'un projet spécifique": extPlaybookChoice, "Changer de branche": branchChoice, "Quitter": None } @@ -162,7 +151,7 @@ def main(): cmdlineOptionPassed = False for entry in config['ansiblemenu']: if entry in list(arg for arg in vars(args) if getattr(args, arg)): - AnsibleActions.runAnsiblePlaybook(config, entry, currentBranch) + AnsibleActions.runAnsiblePlaybook(config, entry) cmdlineOptionPassed = True