48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
import socket
|
|
import subprocess
|
|
import os
|
|
import glob
|
|
|
|
def runAnsiblePlaybook(config, playbook, branch):
|
|
subprocess.run(['ansible-playbook', config['playbook'][playbook]], check=True, cwd=config['base_path'])
|
|
|
|
def getHostName():
|
|
return socket.gethostname()
|
|
|
|
def getDomain():
|
|
domainname = subprocess.check_output(['domainname', '-d'], text=True).rstrip()
|
|
return domainname
|
|
|
|
def isCompliant():
|
|
return False
|
|
|
|
def setFQDN(fqdn):
|
|
result = subprocess.run(['hostnamectl', 'hostname', fqdn], check=True)
|
|
return result.returncode == 0
|
|
|
|
|
|
def runCompliance(config, branch):
|
|
runAnsiblePlaybook(config, 'compliance', branch)
|
|
|
|
def runCubic(config, branch):
|
|
runAnsiblePlaybook(config, 'cubic', branch)
|
|
|
|
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
|