Salt States for the Homelab

Over the past year or so I have been playing around with saltstack to automate as much as I possibly can in my lab, from updates to base vm configuration and making lab wide configuration changes (such as setting up SNMP for monitoring).  Here are my collection of states I currently use to carry out that baseline setup, they are all called from within my top.sls so at highstate they all are applied and make things suck just a little less when running updates and helps prevent typos from making things take longer than necessary.

user.sls

dword:
  user.present:
    - password: $1$hud1CQZ8$eBQ/vZhwxfgIbLP/UbQzA.
/etc/sudoers:
  file.append:
    - text:
      - "# added via salt"
      - "dword ALL=(ALL)       ALL"

snmp.sls

net-snmp:
  pkg.installed: []
snmpd:
  service:
    - enable: True
    - running

repo.sls

updates:
  pkgrepo.managed:
    - humanname: CentOS-$releasever - Updates
    - baseurl: http://192.168.1.50/centos/7/updates
    - gpgcheck: 1
    - gpgkey: file:///etc/pki/rpm-gpg/RPM_GPG-KEY-CentOS-7

packages.sls

wget:
  pkg.installed: []
bind-utils:
  pck.installed: []

 

And finally my favorite of all, a working curl from within a state to hit an API target to kick off discovery, in this case its a discovery within EM7 but it can be easily modified as necessary

# this will perform a curl on the target minion
do_a_curl:
  cmd.run:
    - name: >-
        curl -k -v -H 'X-em7-beautify-response:1' -u 'dword:somepass' "https://192.168.1.65/api/discovery_session_active" -H 'content-type:application/em7-resource-uri' --data-binary "/api/discovery_session/1"

 

Leave a Comment

Close Bitnami banner
Bitnami