Search code examples
salt-project

SaltStack : Identify environment with DNS record


I have multiple isolated environments to setup with SaltStack. I have created some base states and custom states for each environment. For the moment, the only way I can identify an environment is by requesting a TXT record on the DNS server. Is there a way I can select the right environment in SaltStack. How can I put this information in a pillar or a grain?


Solution

  • Salt's dig module might help you here. You can use it to query information from DNS records. It needs the command line dig tool to be installed.

    Use a command line:

    salt-call dig.TXT google.com
    

    to produce an output like this:

    local:
        - "v=spf1 include:_spf.google.com ~all"
    

    Use a salt state to put it into a grain:

    # setupgrain.sls
    mygrainname:
      grains.present:
        - value: {{ salt['dig.TXT']('google.com') }}
    

    Once you have the information in a grain you can select salt nodes on the grain information using matchers.