16 February 2016

Salt: Control a Linux Minion

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':
  1. Create the needed directories for the config files:
    mkdir /srv/salt
  2. Uncomment/add the necessary lines in the master config file:
    vi /etc/salt/master
    #Find file_roots: /fileroots
    file_roots:
      base:
        - /srv/salt
  3. Restart the master to enable the change:
    pkill salt-master
    salt-master -d

Create the 'top' file:

  1. Create a 'top.sls' file:
    vi /srv/salt/top.sls
  2. 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

  1. Create the ubuntu state files:
    vi /srv/salt/global.sls
    vi /srv/salt/salt/minion.sls
    vi /srv/salt/repos/ubuntu.sls
  2. 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

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

Running Commands on the Minion

No comments:

Post a Comment