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 }