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

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
主站蜘蛛池模板: 卫辉市| 西吉县| 泌阳县| 寿宁县| 贵州省| 正安县| 江口县| 襄城县| 罗山县| 郴州市| 青冈县| 维西| 深水埗区| 澎湖县| 安新县| 乌审旗| 靖州| 博白县| 镇赉县| 措勤县| 晋江市| 榕江县| 双鸭山市| 郑州市| 沽源县| 班戈县| 龙井市| 姚安县| SHOW| 新余市| 万州区| 定州市| 曲沃县| 邹城市| 巧家县| 望奎县| 芮城县| 资溪县| 郁南县| 台江县| 诸暨市|