From d627582075fb15bc3a812e38c6ec3c367761b877 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Thu, 26 Jan 2023 18:58:09 +0100 Subject: Read formulas from central file - add formulas.yaml file containing list of all enabled formulas - read formulas from said file in role.salt.master and prepare_minion.py - add symlink for easier tracking of the file Signed-off-by: Georg Pfuetzenreuter --- bin/prepare_minion.py | 24 ++++++++++++++---------- formulas.yaml | 1 + pillar/formulas.yaml | 3 +++ pillar/role/salt/master.sls | 2 +- 4 files changed, 19 insertions(+), 11 deletions(-) create mode 120000 formulas.yaml create mode 100644 pillar/formulas.yaml diff --git a/bin/prepare_minion.py b/bin/prepare_minion.py index a1f15bd..92d45c5 100755 --- a/bin/prepare_minion.py +++ b/bin/prepare_minion.py @@ -5,13 +5,17 @@ import roles import os import yaml import socket +import yaml roles = roles.get() grainsfile = '/etc/salt/grains' -idfile = 'pillar/id/' + socket.gethostname() + '.sls' +idfile = os.path.join('pillar/id/', socket.gethostname() + '.sls') configfile = '/etc/salt/minion.d/local.conf' mypwd = os.getcwd() +formulasfile = 'formulas.yaml' +formulasdir = '/srv/formulas' +configdata = {'file_roots': {'production': ['/srv/salt']}} grainsdata = {'roles': roles} with open(grainsfile, mode='w') as grainsfh: @@ -20,16 +24,16 @@ with open(grainsfile, mode='w') as grainsfh: with open(idfile, mode='w') as idfh: idfh.write('# empty') -# to-do: include formulas automatically, maybe from some YAML file? +with open(formulasfile, mode='r') as formulasfh: + formulas = yaml.load(formulasfh, Loader=yaml.FullLoader) + +for formula in formulas: + formula = os.path.join('/srv/formulas/', formula + '-formula') + configdata['file_roots']['production'].append(formula) + with open(configfile, mode='w') as configfh: - configfh.write('''# written by prepare_minion.py -file_roots: - production: - - /srv/salt - - /srv/formulas/salt-formula - - /srv/formulas/users-formula - - /srv/formulas/postfix-formula -''') + configfh.write('# written by prepare_minion.py\n') + yaml.dump(configdata, configfh) os.symlink(mypwd + '/salt', '/srv/salt') os.symlink(mypwd + '/pillar', '/srv/pillar') diff --git a/formulas.yaml b/formulas.yaml new file mode 120000 index 0000000..46a0cb0 --- /dev/null +++ b/formulas.yaml @@ -0,0 +1 @@ +pillar/formulas.yaml \ No newline at end of file diff --git a/pillar/formulas.yaml b/pillar/formulas.yaml new file mode 100644 index 0000000..a9095f1 --- /dev/null +++ b/pillar/formulas.yaml @@ -0,0 +1,3 @@ +- postfix +- salt +- users diff --git a/pillar/role/salt/master.sls b/pillar/role/salt/master.sls index 49785ac..e66774f 100644 --- a/pillar/role/salt/master.sls +++ b/pillar/role/salt/master.sls @@ -1,4 +1,4 @@ -{%- set formulas = ['salt', 'users', 'postfix'] -%} +{%- import_yaml 'formulas.yaml' as formulas -%} include: - role.salt.common -- cgit v1.2.3