Dec 302015
 

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
Running the salt-key -a pi command will accept the key.

# salt-key
Accepted Keys:
Denied Keys:
Unaccepted Keys:
pi
Rejected Keys:

# salt-key -a pi
The following keys are going to be accepted:
Unaccepted Keys:
pi
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
pi:
True

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.

snmpd:
pkg:
- installed
service.running:
- watch:
- file: /etc/snmp/snmpd.conf
- require:
- pkg: snmpd

/etc/snmp/snmpd.conf:
file:
- managed
- source: salt://pi/snmpd.conf
- require:
- 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
----------
ID: snmpd
Function: pkg.installed
Result: True
Comment: The following packages were installed/updated: snmpd.
Started:
Duration:
Changes:
----------
snmpd:
----------
new:
5.7.2.1+dfsg-1
old:

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!

Share

  4 Responses to “Managing My Raspberry Pi With Saltstack”

  1. I have salt set up on my pi device also. But, the salt-minion keeps turning itself off on its own about 1-2 minutes after it is started.. Did you run into that?

  2. You need to fix the formatting of your sls file.

    The leading spaces are important.

    • Thanks for letting me know, I think it might just be WordPress stripping whitespaces that’s meant to be there

Leave a Reply to John MacDowall Cancel reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

This site uses Akismet to reduce spam. Learn how your comment data is processed.