- Salt Cookbook
- Anirban Saha
- 599字
- 2021-07-16 13:21:56
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...
- 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
- Create a pillar directory
user
in the base pillar directory, and in it create the fileinit.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'
- 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
- 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
- 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'
- Run the following command to refresh the pillar data on the minion:
salt 'salt-minion' saltutil.refresh_pillar
- 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
- 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
- Advanced Quantitative Finance with C++
- Django+Vue.js商城項目實戰(zhàn)
- 大學計算機應用基礎(chǔ)實踐教程
- Learning ArcGIS Pro 2
- Rust編程從入門到實戰(zhàn)
- Mastering Python High Performance
- 微信小程序入門指南
- Unity Game Development Scripting
- HTML5秘籍(第2版)
- Couchbase Essentials
- Xcode 6 Essentials
- 深入解析Java編譯器:源碼剖析與實例詳解
- Flink技術(shù)內(nèi)幕:架構(gòu)設計與實現(xiàn)原理
- Hacking Android
- Flink入門與實戰(zhàn)