The SD Card on my Raspberry Pi died this week. So I decided that this time, I’d use Salt to manage my Pi and not have to worry about backing up my configuration from the Pi itself as Salt would be managing it for me!
I used the Raspbian Unattended Netinstaller to give me the most minimal image possible.
If you use this installer, make sure you set up the image to install Jessie rather than the default Wheezy distribution to get the correct version of the salt minion.
Once Raspbian was done installing, I needed to install the Salt minion. I could have setup the netboot installer to install it as well, but doing it manually will work for any old Raspbian Jessie install.
# apt-get install salt-minion
After installing the salt-minion, you’ll need to do some configuration to get the Pi talking to the Salt Master if you’re not using the default hostname of
salt for your Salt master.
The configuration file should be
/etc/salt/minion, and you’ll need to modify the
master parameter in the configuration file.
After modifying the configuration, be sure to restart the Salt minion.
Back onto the Salt master, you should now be able to see the Pi asking to add the key
salt-key -a pi command will accept the key.
# salt-key -a pi
The following keys are going to be accepted:
Proceed? [n/Y] y
Key for minion pi accepted.
After the key is accepted, you should be able to poll the Pi with a Salt ping to verify a connection is working
# salt 'pi' test.ping
I’ve setup the following SLS file for the Pi to get its configuration from.
This SLS just sets up the basic SNMP configuration that I require, which is a few updates to the snmp configuration and uploading the configuration to the Pi itself.
- file: /etc/snmp/snmpd.conf
- pkg: snmpd
- source: salt://pi/snmpd.conf
- pkg: snmpd
To deploy the configuration, run the
salt 'pi' state.highstate command.
Once the command finishes running, you should get some output like so –
# salt 'pi' state.highstate
Comment: The following packages were installed/updated: snmpd.
The above output signifies that the snmp package was installed. You’ll also get some other output for the
snmpd.conf file being uploaded to the Pi.
Now that the SNMP configuration is managed by Salt – I can restore the configuration as I need for my Raspberry Pi that I’m using as a temperature sensor
Most of the configuration that I used was based on The Saltstack tutorials, and some Googling.
Feel free to ask questions in the comments!