diff options
author | Georg Pfuetzenreuter | 2023-01-26 18:58:09 +0100 |
---|---|---|
committer | Georg Pfuetzenreuter | 2023-01-26 20:54:09 +0100 |
commit | d627582075fb15bc3a812e38c6ec3c367761b877 (patch) | |
tree | 60a74a327fccb8ef96cff582b35f2dab87ea7dc5 /bin/prepare_minion.py | |
parent | 68939f80548446b1e1f44a62e98cc97d6552d2ff (diff) | |
download | salt-d627582075fb15bc3a812e38c6ec3c367761b877.tar.gz salt-d627582075fb15bc3a812e38c6ec3c367761b877.tar.bz2 salt-d627582075fb15bc3a812e38c6ec3c367761b877.zip |
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 <mail@georg-pfuetzenreuter.net>
Diffstat (limited to 'bin/prepare_minion.py')
-rwxr-xr-x | bin/prepare_minion.py | 24 |
1 files changed, 14 insertions, 10 deletions
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') |