salt/bin/prepare_minion.py
Georg Pfuetzenreuter 97db5ef6db
Add nbroles_to_grains script + add note
Script allows for testing and pipeline minions to work without access to
the roles API. Additionally added a note about this in prepare_minion.py.

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
2023-01-21 18:54:58 +01:00

24 lines
712 B
Python
Executable File

#!/usr/bin/env python3
# Prepares a minion for local testing of Salt code in this repository. Requires roles to be written as grains, as development and pipeline containers generally do not have access to our roles API. Consider nbroles_to_grains.sh first if this is the case.
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')