tags
This commit is contained in:
parent
20146f417d
commit
21f811ef68
5 changed files with 47 additions and 15 deletions
|
@ -10,6 +10,8 @@ required_packages:
|
|||
- nemo-image-converter
|
||||
- nemo-nextcloud
|
||||
- nemo-audio-tab
|
||||
- gpaste-2
|
||||
- gir1.2-gpaste-2
|
||||
|
||||
remove_packages:
|
||||
- mintchat
|
||||
|
|
|
@ -33,11 +33,13 @@ ansible_playbooks:
|
|||
|
||||
update:
|
||||
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
|
||||
playbook: update.yml
|
||||
|
||||
conformite:
|
||||
menu_title: Exécuter la configuration du poste
|
||||
tags: [ firstboot ]
|
||||
argument_help: Ne présente pas le menu et exécute la conformité
|
||||
playbook: conformite.yml
|
||||
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
set -eo pipefail
|
||||
logger -t linuxinstaller "Exécution de linuxinstaller-firstboot.sh"
|
||||
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
|
||||
|
|
|
@ -3,22 +3,38 @@ import json
|
|||
from InquirerPy import inquirer
|
||||
from InquirerPy import prompt
|
||||
|
||||
def runAnsiblePlaybook(config, key):
|
||||
extra_vars={}
|
||||
def runAnsiblePlaybook(config, key, extra_vars={}):
|
||||
extra_vars = extra_vars.copy()
|
||||
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')
|
||||
extra_vars[var_name] = prompt(question)[0]
|
||||
|
||||
if 'extra_vars' in config['ansible_playbooks'][key]:
|
||||
extra_vars = extra_vars | config['ansible_playbooks'][key]['extra_vars']
|
||||
|
||||
if len(extra_vars) > 0:
|
||||
subprocess.check_call(['ansible-playbook', config['ansible_playbooks'][key]['playbook'],
|
||||
'--extra-vars', json.dumps(extra_vars) ],
|
||||
cwd=config['base_path'])
|
||||
if 'playbook_url' in config['ansible_playbooks'][key]:
|
||||
runPulledAnsiblePlaybook(config['ansible_playbooks'][key]['playbook'],
|
||||
config['ansible_playbooks'][key]['playbook_url'],
|
||||
extra_vars)
|
||||
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])
|
||||
|
|
|
@ -91,7 +91,7 @@ def extPlaybookChoice():
|
|||
confirm_letter = "o",
|
||||
default=False).execute()
|
||||
if proceed:
|
||||
AnsibleActions.pullAnsiblePlaybook(url, playbook)
|
||||
AnsibleActions.runPulledAnsiblePlaybook(playbook, url)
|
||||
else:
|
||||
print("Annulation")
|
||||
|
||||
|
@ -126,7 +126,9 @@ def main():
|
|||
config = readConfig("config.yml")
|
||||
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']:
|
||||
if 'argument_help' in config['ansible_playbooks'][entry]:
|
||||
parser.add_argument("--" + entry, help=config['ansible_playbooks'][entry]['argument_help'], action='store_true')
|
||||
|
@ -152,7 +154,17 @@ def main():
|
|||
# Exécute les options passées sur la ligne de commande
|
||||
cmdlineOptionPassed = False
|
||||
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)):
|
||||
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)
|
||||
cmdlineOptionPassed = True
|
||||
|
||||
|
|
Loading…
Reference in a new issue