Préparation ansible-pull
This commit is contained in:
parent
51e3e2d2ce
commit
952f44abf2
2 changed files with 42 additions and 21 deletions
|
@ -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'])
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue