Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
Georg Pfuetzenreuter 2023-01-15 09:18:15 +01:00
commit f1a4b0514c
Signed by: Georg
GPG Key ID: 1ED2F138E7E6FF57
4 changed files with 59 additions and 0 deletions

22
bin/prepare_minion.py Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python3
import roles
import os
import yaml
import socket
roles = roles.get()
grainsfile = '/etc/salt/grains'
idfile = 'pillar/id/' + socket.gethostname() + '.sls'
mypwd = os.getcwd()
grainsdata = {'roles': roles}
with open(grainsfile, mode='w') as grainsfh:
yaml.dump(grainsdata, grainsfh)
with open(idfile, mode='w') as idfh:
idfh.write('# empty')
os.symlink(mypwd + '/salt', '/srv/salt')
os.symlink(mypwd + '/pillar', '/srv/pillar')

13
bin/prepare_mock.py Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env python3
import os
import shutil
import socket
iddir = 'pillar/id/'
secretiddir = 'pillar/secret/id/'
baseidfile = 'atvkdev02_home_lysergic_dev.sls'
myidfile = socket.gethostname() + '.sls'
shutil.copyfile(iddir + baseidfile, iddir + myidfile)
shutil.copyfile(secretiddir + baseidfile, secretiddir + myidfile)

13
bin/roles.py Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env python3
import os
roles = []
excluded = ['common-suse', 'minion']
def get():
for file in os.listdir('salt/role'):
role = os.path.splitext(file)[0]
if not role in excluded:
roles.append(role)
return roles

11
salt/top.sls Normal file
View File

@ -0,0 +1,11 @@
{% set client_id = salt['grains.get']('id') %}
{% set roles = salt['grains.get']('roles', []) %}
{{ saltenv }}:
'*':
- baseline
{% for role in roles %}
'roles:{{ role }}':
- match: grain
- role.{{ role }}
{% endfor %}