From f1a4b0514c148d9b5477f5c2b11938445e4438b1 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Sun, 15 Jan 2023 09:18:15 +0100 Subject: [PATCH] Init Signed-off-by: Georg Pfuetzenreuter --- bin/prepare_minion.py | 22 ++++++++++++++++++++++ bin/prepare_mock.py | 13 +++++++++++++ bin/roles.py | 13 +++++++++++++ salt/top.sls | 11 +++++++++++ 4 files changed, 59 insertions(+) create mode 100755 bin/prepare_minion.py create mode 100755 bin/prepare_mock.py create mode 100755 bin/roles.py create mode 100644 salt/top.sls diff --git a/bin/prepare_minion.py b/bin/prepare_minion.py new file mode 100755 index 0000000..e89434a --- /dev/null +++ b/bin/prepare_minion.py @@ -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') diff --git a/bin/prepare_mock.py b/bin/prepare_mock.py new file mode 100755 index 0000000..982ca32 --- /dev/null +++ b/bin/prepare_mock.py @@ -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) diff --git a/bin/roles.py b/bin/roles.py new file mode 100755 index 0000000..1777f8c --- /dev/null +++ b/bin/roles.py @@ -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 diff --git a/salt/top.sls b/salt/top.sls new file mode 100644 index 0000000..de9b24b --- /dev/null +++ b/salt/top.sls @@ -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 %}