To control a Salt Minion after install and configuration, setup a state tree:
Configure the Salt Master
In this example we will define two environments: base and 'ubuntu'
Enable these environments via the 'top file':
Enable these environments via the 'top file':
- Create the needed directories for the config files:
mkdir /srv/salt - Uncomment/add the necessary lines in the master config file:
vi /etc/salt/master
#Find file_roots: /filerootsfile_roots:base:- /srv/salt - Restart the master to enable the change:
pkill salt-master
salt-master -d
Create the 'top' file:
- Create a 'top.sls' file:
vi /srv/salt/top.sls - Add in the declarations the environment:
base:
'*':
- global
- salt.minion
'os:Ubuntu':
- match: grain
- linux/ubuntu
This tells salt that for the environment called base all minions will have state files /srv/salt/global.sls and /srv/salt/salt/minion.sls applied to them.
All systems that match the 'grain' of Ubuntu all Minions will have the state file /srv/salt/linux/ubuntu.sls or /srv/salt/linux/ubuntu/init.sls applied to them.
Create the State Files
- Create the ubuntu state files:
vi /srv/salt/global.sls
vi /srv/salt/salt/minion.sls
vi /srv/salt/repos/ubuntu.sls - Create the ubuntu state tree:
vi /srv/salt/repos/ubuntu.sls
unattended-upgrades: # ID declaration
pkg: # state declaration
- installed # function declaration
Configure the Salt Minion
Use Cron on the Minion to enforce the Salt Master configuration:
sudo crontab -e
Insert the following line to run it hourly:
00 * * * * salt-call state.highstate
You can also issue this command manually from the Salt Master:
salt '*' state.highstate
or on the Minion:
salt-call state.highstate
salt '*' state.highstate
or on the Minion:
salt-call state.highstate
Troubleshooting
salt-minion -l debug & # On the Minion
salt '*' state.highstate -t 60 # On the Master
Useful Commands
- Get all services available for configuration on a Minion:
salt [Minion hostname] service.get_all
No comments:
Post a Comment