Préparation ansible-pull

This commit is contained in:
Navas 2024-10-08 12:19:49 +02:00
parent 952f44abf2
commit de8c9f3fc6
2 changed files with 16 additions and 29 deletions

View file

@ -1,9 +1,7 @@
import subprocess
import os
import glob
def runAnsiblePlaybook(config, key, branch):
subprocess.run(['ansible-playbook', config['ansiblemenu'][key]['playbook']], check=True, cwd=config['base_path'])
def runAnsiblePlaybook(config, key):
subprocess.check_call(['ansible-playbook', config['ansiblemenu'][key]['playbook']], 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])

View file

@ -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"))
).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",
(playbook.endswith(".yaml") or playbook.endswith(".yml")),
invalid_message = "Un nom de playbook doit se terminer par .yml ou .yaml"
).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