Created
January 24, 2018 12:39
-
-
Save ryanwalder/d56b9d43c95c9aa5250207fa45c58827 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get full minion id, should be fqdn | |
{%- set id = salt.grains.get('id') %} | |
# Get the hostname | |
{%- set sid = id.split('.')[0] %} | |
# Break down the hostname into the chunks we need to generate the pillar | |
# folder structure | |
{%- set use = sid[0:3] %} # use: not used within pillar ATM | |
{%- set platform = sid[3:6] %} # platform | |
{%- set component = sid[6:9] %} # component | |
{%- set os = sid[8] %} # os | |
{%- set number = sid[9:10] %} # number | |
{%- set env = sid[11] %} # environment | |
# Get the full domain | |
{%- set domain = id.split('.')[1:]|join('.') %} | |
# List of all environments, used for applying anti environment pillar | |
{%- set environments = ['v', 'd', 'q', 's', 'p', 'c'] %} | |
# Checks if a file exists in the following places: | |
# global/init.sls | |
# global/virtual/init.sls | |
# global/os/os/init.sls | |
# global/os/os/family/init.sls | |
# global/os/os/family/release/init.sls | |
# global/environment/env/init.sls | |
# global/environment/env/anti.sls | |
# global/component/init.sls | |
# platform/init.sls | |
# platform/environment/init.sls | |
# platform/environment/anti.sls | |
# platform/component/init.sls | |
# platform/component/environment/init.sls | |
# platform/component/environment/anti.sls | |
# platform/component/environment/number/init.sls | |
# NOTE: Ordering of the file lookups below is very important! | |
# If you define the same pillar keypairs in multiple files the last loaded wins | |
# This allows defaults to be set higher up with per component, platform, and env overrides | |
# Due to the file_exists checks below we can't use gitfs for pillar | |
# The other way around this would be blank init.sls files in every possible | |
# location which is way too messy. | |
base: | |
'*': | |
# Pillar for everything | |
- global | |
# Global virtualization platform: (vmware, virtualbox etc...) | |
{%- if salt.pillar.file_exists('global/virt/' + salt.grains.get('virtual')|lower + '/init.sls') %} | |
- global.virt.{{ salt.grains.get('virtual')|lower }} | |
{%- endif %} | |
# Global OS Family: (redhat, debian etc...) | |
{%- if salt.pillar.file_exists('global/os/' + salt.grains.get('os_family')|lower + '/init.sls') %} | |
- global.os.{{ salt.grains.get('os_family')|lower }} | |
{%- endif %} | |
# Global per OS codename (7, xenial etc...) | |
{%- if salt.pillar.file_exists('global/os/' + salt.grains.get('os_family')|lower + '/' + salt.grains.get('oscodename')|lower + '/init.sls') %} | |
- global.os.{{ salt.grains.get('os_family')|lower }}.{{ salt.grains.get('oscodename')|lower }} | |
{%- endif %} | |
# Global environment: Globally within an environment | |
# ------------p.prd.example.com | |
{%- if salt.pillar.file_exists('global/environment/' + env + '/init.sls') %} | |
- global.environment.{{ env }} | |
{%- endif %} | |
# Global anti environment: Globally not in an environment. EG: "not vagrant" or "not prod" | |
# NOT ------------p.prd.example.com | |
{%- for environment in environments %} | |
{%- if salt.pillar.file_exists('global/environment/' + environment + '/anti.sls') %} | |
{%- if env != environment %} | |
- global.environment.{{ environment }}.anti | |
{%- endif %} | |
{%- endif %} | |
{%- endfor %} | |
# Global tech: Global setting for a component | |
# ------XXX----.---.example.com | |
{%- if salt.pillar.file_exists('global/tech/' + component + '/init.sls') %} | |
- global.tech.{{ component }} | |
{%- endif %} | |
# Platform | |
# ---XXX-------.---.example.com | |
{%- if salt.pillar.file_exists(platform + '/init.sls') %} | |
- {{ platform }} | |
{%- endif %} | |
# Service, environment: Overrides enviroment specific to a service | |
# ---XXX------p.prd.example.com | |
{%- if salt.pillar.file_exists(platform + '/' + env + '/init.sls') %} | |
- {{ platform }}.{{ env }} | |
{%- endif %} | |
# Service, anti environment: not in an environment but within a service. | |
# EG: "in bitbucket, not vagrant" or "in jenkins, not prod" | |
# NOT ---XXXYYY---p.prd.example.com | |
{%- for environment in environments %} | |
{%- if salt.pillar.file_exists(platform + '/' + environment + '/anti.sls') %} | |
{%- if env != environment %} | |
- {{ platform }}.{{ environment }}.anti | |
{%- endif %} | |
{%- endif %} | |
{%- endfor %} | |
# platform, component | |
# ---XXXYYY----.---.example.com | |
{%- if salt.pillar.file_exists(platform + '/' + component + '/init.sls') %} | |
- {{ platform }}.{{ component }} | |
{%- endif %} | |
# Overrides for environment within a platform within a component | |
# ---XXXYYY---p.prd.example.com | |
{%- if salt.pillar.file_exists(platform + '/' + component + '/' + env + '/init.sls') %} | |
- {{ service }}.{{ tech }}.{{ env }} | |
{%- endif %} | |
# Platform, component anti environment: not in an environment but within a platform and component. | |
# EG: "nginx, in bitbucket, not vagrant" or "tomcat, in jenkins, not prod" | |
# NOT ---XXXYYY---p.prd.example.com | |
{%- for environment in environments %} | |
{%- if salt.pillar.file_exists(platform + '/' + component + '/' + environment + '/anti.sls') %} | |
{%- if env != environment %} | |
- {{ platform }}.{{ component }}.{{ environment }}.anti | |
{%- endif %} | |
{%- endif %} | |
{%- endfor %} | |
# Overides for a node within a tech, within a service, within an environment | |
# ---XXXYYY-NN-.---.example.com | |
{%- if salt.pillar.file_exists(platform + '/' + component + '/' + env + '/' + number + '/init.sls') %} | |
- {{ platform }}.{{ component }}.{{ env }}.{{ number }} | |
{%- endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment