Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
75 lines (59 sloc) 2.41 KB

salt-grains-environment

My solution to managing what environment my computers are in.

The folder structure here mimics how the file should sit in the file_root. For example, the _grains folder is same _grains folder referenced in the grains doc.

Usage

Using this is pretty straight forward. In my environment, the prd environment is the default environment (Note: base still exists, but is considere global). We have two other environments:

  • dev
  • pre

The dev environment houses development/test machines that may be working in a broken state at any given time. The computer in the pre environment are our guinea pigs -- where we test what we believe is a working config before releasing to production (prd).

In order to have this work in your environment, you will first need to configure your file_roots (more info) and pillar_roots in your master config file. Here's mine, as an example:

file_roots:
  base:
    - /srv/salt
    - /srv/salt/prd
  dev:
    - /srv/salt/dev
    - /srv/salt/pre
    - /srv/salt/prd
  pre:
    - /srv/salt/pre
    - /srv/salt/prd
  prd:
    - /srv/salt/prd

pillar_roots:
  base:
    - /srv/pillar
    - /srv/pillar/prd
  dev:
    - /srv/pillar/dev
    - /srv/pillar/pre
    - /srv/pillar/prd
  pre:
    - /srv/pillar/pre
    - /srv/pillar/prd
  prd:
    - /srv/pillar/prd

That's it! From now on, to add a computer to an environment, simply add the computer's hostname the the respective list:

top.sls

This is a sample of SaltStack's top file. This will show you how to reference the grain created in this repo:

base:
  '*':
    - global

prd:
  'environment:prd':
    - match: grain
    - apps.salt-minion

pre:
  'environment:pre':
    - match: grain
    - apps.dsconfigad

dev:
  'environment:dev':
    - match: grain
    - apps.testapp