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

Writing and retrieving pillar data

We already have a basic understanding of what pillars are and how to use them in Salt. In this section, we are going to learn more about writing pillars and how to retrieve them both from the master and the minion.

How to do it...

  1. Create a new environment qa using the recipe Configuring the Salt environment and pillar paths in Chapter 1, Salt Architecture and Components. The state environment path should be /opt/salt-cookbook/qa, and the pillar path should be /opt/salt-cookbook/pillar/qa. Also, create the top files for the new environment in the base directory for state and the pillar, and populate them with the following entry:
    qa:
      '*':
        - user
  2. Create a pillar directory user in the base pillar directory, and in it create the file init.sls. Edit /opt/salt-cookbook/pillar/qa/user/init.sls and enter the following:
    users:
      qa_user: qa-app
      qa_user_password: '$1$lhxadPoh$d5tZktsF/eI08tqiwmwBo0'
  3. Configure the minion using the recipe Configuring environments and grains on the minion in Chapter 1, Salt Architecture and Components, with the environment as qa and the grains as follows:
    server_type: app
    environment: qa
  4. Run the following command to view the pillar items for the minion:
    [root@salt-master ~]# salt 'salt-minion' pillar.items
    salt-minion:
        ----------
        master:
            ----------
            auth_mode:
                1
        .
        .
        users:
            ----------
            qa_user:
                qa-app
            qa_user_password:
                $1$lhxadPoh$d5tZktsF/eI08tqiwmwBo0
  5. Reopen /opt/salt-cookbook/pillar/qa/user/init.sls and edit the file to have the following contents:
    users:
      qa_user: qa-app
      qa_user_password: '$1$lhxadPoh$d5tZktsF/eI08tqiwmwBo0'
      admin_user_passwd: '$1$0gH3Ry2s$sMc9yVAC9iyr/yEF/ggbr0'
  6. Run the following command to refresh the pillar data on the minion:
    salt 'salt-minion' saltutil.refresh_pillar
    
  7. Rerun the following command:
    [root@salt-master ~]# salt 'salt-minion' pillar.items
    salt-minion:
     ----------
     master:
     .
     .
     users:
     ----------
     qa_user:
     qa-app
     qa_user_password:
     $1$lhxadPoh$d5tZktsF/eI08tqiwmwBo0
     admin_user_passwd:
     $1$0gH3Ry2s$sMc9yVAC9iyr/yEF/ggbr0
    
  8. On the minion, run the following command to get the pillar data:
    [root@salt-minion ~]# salt-call pillar.get users
    local:
     ----------
     admin_user_passwd:
     $1$0gH3Ry2s$sMc9yVAC9iyr/yEF/ggbr0
     qa_user:
     qa-app
     qa_user_passwd:
     $1$lhxadPoh$d5tZktsF/eI08tqiwmwBo0
    

How it works...

In this recipe, we first created a new environment called qa. Next, we created a new pillar called users and the necessary files for the pillar and the top file using recipes from Chapter 1, Salt Architecture and Components. We also configured our minion to be in the qa environment.

We then wrote a pillar file with very basic information consisting of a username and password:

users:
  qa_user: qa-app
  qa_user_password: '$1$lhxadPoh$d5tZktsF/eI08tqiwmwBo0'

Next, we retrieved the pillar data for this specific minion on the master with the following command using the pillar.items module:

[root@salt-master ~]# salt 'salt-minion' pillar.items

We get a long output showing all the master configuration parameters available to this minion and, at the end, it shows the pillar data available to it. Next, we added a new pillar key-value pair:

admin_user_passwd: '$1$0gH3Ry2s$sMc9yVAC9iyr/yEF/ggbr0'

Next, we run the following command to refresh the pillar data on the minion and recognize the newly added pair:

salt 'salt-minion' saltutil.refresh_pillar

When we retrieve the pillar data on the master, it shows the newly added pair in the list. Do note that most of the time, refresh is not needed. The minion will automatically identify the newly added pillar data, this procedure needs to be followed if it does not do so.

In the end, we run the following command to get the same pillar data available to the minion, but it runs on the minion using the salt-call binary:

[root@salt-minion ~]# salt-call pillar.get users

Do note that in this command, the name of the pillar, that is, users is mandatory, without which an error message will be displayed.

See also

  • The Configuring the Salt environment and pillar paths and Understanding and configuring salt pillars recipes in Chapter 1, Salt Architecture and Components, to understand more about configuring pillars
  • The Using pillar data in states recipe to learn about the various methods to use the configured pillars in states
主站蜘蛛池模板: 社旗县| 南江县| 太谷县| 宜黄县| 博兴县| 繁昌县| 昆明市| 峨山| 宝丰县| 尚义县| 长武县| 竹溪县| 灯塔市| 赤城县| 鹤庆县| 隆化县| 绥棱县| 湖北省| 永登县| 五河县| 邵阳市| 镇原县| 新津县| 蓝田县| 繁峙县| 鞍山市| 星座| 鄂托克旗| 肃宁县| 田阳县| 抚远县| 佛学| 赤峰市| 高唐县| 雷州市| 新巴尔虎左旗| 株洲市| 河北区| 松原市| 苍南县| 奉节县|