From 952f44abf2646d00dff6739ec368fc2c22e7c16c Mon Sep 17 00:00:00 2001 From: Olivier Date: Mon, 7 Oct 2024 14:05:53 +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 | 21 ++--------------- libreticmenu/libreticmenu.py | 42 ++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/libreticmenu/AnsibleActions.py b/libreticmenu/AnsibleActions.py index 372b6c7..4f31685 100644 --- a/libreticmenu/AnsibleActions.py +++ b/libreticmenu/AnsibleActions.py @@ -5,22 +5,5 @@ import glob def runAnsiblePlaybook(config, key, branch): subprocess.run(['ansible-playbook', config['ansiblemenu'][key]['playbook']], check=True, cwd=config['base_path']) -def addLocalAdmin(config, user): - result = subprocess.run( - ['ansible-playbook', - 'ansible/configure-local-admin.yml', - '--extra-vars', str({'user': user, 'state': 'present'})], - check=True) - -def removeLocalAdmin(config, user): - result = subprocess.run( - ['ansible-playbook', - 'ansible/configure-local-admin.yml', - '--extra-vars', str({'user': user, 'state': 'absent'})], - check=True) - -def getLocalAdmins(config): - prefix = '/etc/sudoers.d/libreticmenu_allow_sudo_' - pathlist = glob.glob(prefix+'*') - userlist = [s[len(prefix):] for s in pathlist] - return userlist +def pullAnsiblePlaybook(config, key, branch): + subprocess.run(['ansible-pull', config['ansiblemenu'][key]['playbook']], check=True, cwd=config['base_path']) diff --git a/libreticmenu/libreticmenu.py b/libreticmenu/libreticmenu.py index 883cd29..aed78c9 100644 --- a/libreticmenu/libreticmenu.py +++ b/libreticmenu/libreticmenu.py @@ -67,6 +67,45 @@ def hostnameChoice(): else: print("Annulation") +### Menu du choix playbook externe +def extPlaybookChoice(): + url = inquirer.text( + 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") + ).execute() + + playbook = inquirer.text( + message = "Renseigner le nom du playbook", + validate = lambda playbook : + len(playbook) > 0 and + (playbook.endswith(".yaml") or playbook.endswith(".yml")) + ).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), + confirm_letter = "o", + default=False).execute() + if proceed: + print("Confirmation") + else: + print("Annulation") + def branchChoice(): questions = [ { @@ -103,8 +142,6 @@ def main(): parser.add_argument("--" + entry, help=config['ansiblemenu'][entry]['argument_help'], action='store_true') args = parser.parse_args() - - menu_main = { "Définir le hostname": hostnameChoice, } @@ -116,6 +153,7 @@ def main(): } menu_main = menu_main | { + "Exécuter un playbook d'un projet externe": extPlaybookChoice, "Changer de branche": branchChoice, "Quitter": None }