This commit is contained in:
Navas 2024-10-20 13:10:52 +02:00
parent 20146f417d
commit 21f811ef68
5 changed files with 47 additions and 15 deletions

View file

@ -10,6 +10,8 @@ required_packages:
- nemo-image-converter - nemo-image-converter
- nemo-nextcloud - nemo-nextcloud
- nemo-audio-tab - nemo-audio-tab
- gpaste-2
- gir1.2-gpaste-2
remove_packages: remove_packages:
- mintchat - mintchat

View file

@ -33,11 +33,13 @@ ansible_playbooks:
update: update:
menu_title: Exécuter la mise à jour des paquets menu_title: Exécuter la mise à jour des paquets
tags: [ firstboot ]
argument_help: Ne présente pas le menu et exécute mise à jour des paquets argument_help: Ne présente pas le menu et exécute mise à jour des paquets
playbook: update.yml playbook: update.yml
conformite: conformite:
menu_title: Exécuter la configuration du poste menu_title: Exécuter la configuration du poste
tags: [ firstboot ]
argument_help: Ne présente pas le menu et exécute la conformité argument_help: Ne présente pas le menu et exécute la conformité
playbook: conformite.yml playbook: conformite.yml

View file

@ -2,5 +2,5 @@
set -eo pipefail set -eo pipefail
logger -t linuxinstaller "Exécution de linuxinstaller-firstboot.sh" logger -t linuxinstaller "Exécution de linuxinstaller-firstboot.sh"
until host git.libretic.fr; do sleep 5; done until host git.libretic.fr; do sleep 5; done
/opt/linuxinstaller/linuxinstaller.sh --update --conformite \ /opt/linuxinstaller/linuxinstaller.sh --tags firstboot \
&& systemctl disable linuxinstaller-firstboot.service && systemctl disable linuxinstaller-firstboot.service

View file

@ -3,22 +3,38 @@ import json
from InquirerPy import inquirer from InquirerPy import inquirer
from InquirerPy import prompt from InquirerPy import prompt
def runAnsiblePlaybook(config, key): def runAnsiblePlaybook(config, key, extra_vars={}):
extra_vars={} extra_vars = extra_vars.copy()
if 'questions' in config['ansible_playbooks'][key]: if 'questions' in config['ansible_playbooks'][key]:
for question in config['ansible_playbooks'][key]['questions']: for question in config['ansible_playbooks'][key]['questions'].copy():
var_name = question.pop('var_name') var_name = question.pop('var_name')
extra_vars[var_name] = prompt(question)[0] extra_vars[var_name] = prompt(question)[0]
if 'extra_vars' in config['ansible_playbooks'][key]: if 'extra_vars' in config['ansible_playbooks'][key]:
extra_vars = extra_vars | config['ansible_playbooks'][key]['extra_vars'] extra_vars = extra_vars | config['ansible_playbooks'][key]['extra_vars']
if len(extra_vars) > 0: if 'playbook_url' in config['ansible_playbooks'][key]:
subprocess.check_call(['ansible-playbook', config['ansible_playbooks'][key]['playbook'], runPulledAnsiblePlaybook(config['ansible_playbooks'][key]['playbook'],
'--extra-vars', json.dumps(extra_vars) ], config['ansible_playbooks'][key]['playbook_url'],
cwd=config['base_path']) extra_vars)
else: else:
subprocess.check_call(['ansible-playbook', config['ansible_playbooks'][key]['playbook']], cwd=config['base_path']) runLocalAnsiblePlaybook(config['ansible_playbooks'][key]['playbook'],
config['base_path'],
extra_vars)
def pullAnsiblePlaybook(url, playbook):
subprocess.check_call(['ansible-pull', '-U', url, playbook]) def runLocalAnsiblePlaybook(playbook, chdir, extra_vars={}):
if len(extra_vars) > 0:
subprocess.check_call(['ansible-playbook', playbook,
'--extra-vars', json.dumps(extra_vars) ],
cwd=chdir)
else:
subprocess.check_call(['ansible-playbook', playbook], cwd=chdir)
def runPulledAnsiblePlaybook(playbook, url, extra_vars={}):
if len(extra_vars) > 0:
subprocess.check_call(['ansible-playbook', playbook,
'--extra-vars', json.dumps(extra_vars) ],
cwd=chdir)
else:
subprocess.check_call(['ansible-pull', '-U', url, playbook])

View file

@ -91,7 +91,7 @@ def extPlaybookChoice():
confirm_letter = "o", confirm_letter = "o",
default=False).execute() default=False).execute()
if proceed: if proceed:
AnsibleActions.pullAnsiblePlaybook(url, playbook) AnsibleActions.runPulledAnsiblePlaybook(playbook, url)
else: else:
print("Annulation") print("Annulation")
@ -125,8 +125,10 @@ def branchChoice():
def main(): def main():
config = readConfig("config.yml") config = readConfig("config.yml")
currentBranch = GitActions.getBranch() currentBranch = GitActions.getBranch()
parser = argparse.ArgumentParser(prog="linuxinstaller.py", description="Menu de configuration Libretic") description="Menu de configuration linuxinstaller"
parser = argparse.ArgumentParser(description=description)
parser.add_argument("--tags", help="Exécute les playbooks portant ces étiquettes", action="extend", nargs="+", type=str)
for entry in config['ansible_playbooks']: for entry in config['ansible_playbooks']:
if 'argument_help' in config['ansible_playbooks'][entry]: if 'argument_help' in config['ansible_playbooks'][entry]:
parser.add_argument("--" + entry, help=config['ansible_playbooks'][entry]['argument_help'], action='store_true') parser.add_argument("--" + entry, help=config['ansible_playbooks'][entry]['argument_help'], action='store_true')
@ -142,7 +144,7 @@ def main():
menu_main = menu_main | { menu_main = menu_main | {
config['ansible_playbooks'][entry]['menu_title']: lambda e=entry: AnsibleActions.runAnsiblePlaybook(config, e) config['ansible_playbooks'][entry]['menu_title']: lambda e=entry: AnsibleActions.runAnsiblePlaybook(config, e)
} }
menu_main = menu_main | { menu_main = menu_main | {
"Exécuter un playbook d'un projet spécifique": extPlaybookChoice, "Exécuter un playbook d'un projet spécifique": extPlaybookChoice,
"Changer de branche": branchChoice, "Changer de branche": branchChoice,
@ -152,7 +154,17 @@ def main():
# Exécute les options passées sur la ligne de commande # Exécute les options passées sur la ligne de commande
cmdlineOptionPassed = False cmdlineOptionPassed = False
for entry in config['ansible_playbooks']: for entry in config['ansible_playbooks']:
mustRun = False
# Teste si la clé est dans la liste des arguments
if entry in list(arg for arg in vars(args) if getattr(args, arg)): if entry in list(arg for arg in vars(args) if getattr(args, arg)):
mustRun = True
# Teste si un élément commun entre les tags mentionnés dans la conf et les tags en argument
if len(args.tags.intersection(entry['tags'])) > 0:
mustRun = True
if mustRun == True:
AnsibleActions.runAnsiblePlaybook(config, entry) AnsibleActions.runAnsiblePlaybook(config, entry)
cmdlineOptionPassed = True cmdlineOptionPassed = True