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

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
主站蜘蛛池模板: 桂平市| 垦利县| 临江市| 察隅县| 嘉峪关市| 永安市| 察哈| 九寨沟县| 汉中市| 凤冈县| 鸡西市| 稷山县| 沙湾县| 荔波县| 新宁县| 莆田市| 陵川县| 无极县| 大竹县| 赣榆县| 宜宾市| 高平市| 抚远县| 固安县| 连平县| 南京市| 巴塘县| 西吉县| 米泉市| 牡丹江市| 瑞安市| 全南县| 肥西县| 海林市| 通州市| 枣庄市| 赣榆县| 石屏县| 六枝特区| 壤塘县| 吉安县|