官术网_书友最值得收藏!

  • Salt Cookbook
  • Anirban Saha
  • 605字
  • 2021-07-16 13:21:54

Configuring the Salt environment and pillar paths

In this recipe, we are going to configure the environment and pillar paths for Salt to use when we mention environments while performing Salt operations. Ideally, any infrastructure should have environments for development, testing, QA, production, and so on, for isolation of respective code and a seamless workflow. Salt enables us to implement this in a few simple steps by providing options to define environments for states and pillars.

How to do it...

In the primary configuration /etc/salt/master file, we will configure the section called file_roots. Under this parameter option, we will name each environment we want to configure and the path of the directory that will contain the configuration files for that environment.

  1. Let's create the directories we want to use as the environment paths and then configure four environments named base, production, staging, and development as follows:
    [root@salt-master ~]# mkdir –p \
    /opt/salt-cookbook/{base,production,staging,development}
    
  2. Edit /etc/salt/master to have following content:
    file_roots:
      base:
        - /opt/salt-cookbook/base
      production:
        - /opt/salt-cookbook/production
      staging:
        - /opt/salt-cookbook/staging
      development:
        - /opt/salt-cookbook/development
  3. Next, we will create the directories we want to use as pillar paths and configure them following the same environment conventions as follows:
    [root@salt-master ~]# mkdir –p \
    /opt/salt- cookbook/pillar/{base,production,staging,development}
    
  4. Edit /etc/salt/master to have following content:
    pillar_roots:
      base:
        - /opt/salt-cookbook/pillar/base
      production:
        - /opt/salt-cookbook/pillar/production
      staging:
        - /opt/salt-cookbook/pillar/staging
      development:
        - /opt/salt-cookbook/pillar/development
  5. We now restart the salt-master daemon for these changes to take effect:
    [root@salt-master ~]# service salt-master restart
    

How it works...

Environments in Salt are designed to keep the configuration files for each environment isolated into respective containers for different stages of deployment such as development, QA, staging, and production. Ideally, the configurations can be written in either of the environments such as staging, and after a proper test phases, they can be migrated to the production environment.

Here, we opted for the /opt/salt-cookbook path to be the base directory of all our configurations. Next, we have chosen four environments for our infrastructure, namely, base, staging, production, and development. The base environment is the default in Salt and the path /srv/salt is taken as the base directory for all configurations if not configured explicitly as we have done earlier.

We then created the directory paths we want to use as the environment paths and mentioned them under the file_roots parameter, specifying the environment name and the path that points the configuration files for that environment:

file_roots:
  <environment_name>:
    - <environment_directory_path>

Pillars are one of the best features of Salt, which enable us to isolate data that needs to be kept secure such as keys and passwords. Next, we have chosen the /opt/salt-cookbook/pillar path to be our base directory for all pillar data and created directories for each environment that will contain pillar data, which is usable in that environment only.

We then edited the Salt master configuration file to include the environment names and their paths under the pillar_roots section for Salt to identify them as the pillar configuration paths:

pillar_roots:
  <environment_name>:
    - <pillar_directory_path>

Finally, we restarted the Salt master daemon for the changes to take effect.

It is also to be noted that when executing the salt command, the environment has to be mentioned for the minion(s). This is generally done with the saltenv option on the command line. However, this parameter can also be specified in the minion configuration /etc/salt/minion file, as follows:

environment: production

If this parameter is not set, the base environment is taken as the default environment.

See also

  • The Using pillar data in states and Writing and retrieving pillar data recipes in Chapter 2, Writing Advanced Salt Configurations, to learn more about how to use pillars in states
  • The Understanding and configuring Salt pillars recipe, for detailed examples of pillar configurations
主站蜘蛛池模板: 东乌珠穆沁旗| 红原县| 阿合奇县| 襄垣县| 丽江市| 长岭县| 康定县| 孝义市| 团风县| 平山县| 德昌县| 宝应县| 惠州市| 泾阳县| 呼玛县| 大理市| 苗栗市| 鸡泽县| 江永县| 元阳县| 通道| 温州市| 香河县| 句容市| 上高县| 双峰县| 攀枝花市| 通化县| 鹰潭市| 大余县| 昌乐县| 林口县| 武威市| 阿拉尔市| 忻州市| 灵丘县| 三都| 独山县| 吉安县| 朔州市| 巴青县|