- Salt Cookbook
- Anirban Saha
- 585字
- 2021-07-16 13:21:57
Testing a state run before applying to minions
Sometimes, even the smallest of typos or mistakes in configurations can create the biggest problems in infrastructure if not tested and checked before applying them. In this recipe, you will learn how to test state configurations before applying them to minions.
How to do it...
We will make use of the minion and states configured in the previous recipe Setting and using variables in states. We will also assume that the minion is a fresh install with no previous configurations applied to it:
- Run the following command:
[root@salt-master ~]# salt 'stgdc1app02' state.sls user \ saltenv=staging test=True stgdc1app02: ---------- ID: cyclonus Function: user.present Result: None Comment: User cyclonus set to be added Changes: ---------- ID: megatron Function: user.present Result: None Comment: User megatron set to be added Changes: Summary ------------ Succeeded: 0 Failed: 0 Not Run: 2 ------------ Total: 2
- On the minion, edit the
/etc/salt/minion
file, uncomment the following line, and restart the minion daemon:test: True
- On the master, run the following command:
[root@salt-master ~]# salt 'stgdc1app02' state.sls user \ saltenv=staging stgdc1app02: ---------- ID: cyclonus Function: user.present Result: None Comment: User cyclonus set to be added Changes: ---------- ID: megatron Function: user.present Result: None Comment: User megatron set to be added Changes: Summary ------------ Succeeded: 0 Failed: 0 Not Run: 2 ------------ Total: 2
- On the master, run the following command:
[root@salt-master ~]# salt 'stgdc1app02' state.sls user \ saltenv=staging --state-output=terse test=False stgdc1app02: Name: cyclonus - Function: user.present - Result: Changed Name: megatron - Function: user.present - Result: Changed Summary ------------ Succeeded: 2 Failed: 0 ------------ Total: 2
How it works...
In this recipe, we demonstrated how to test our configuration before applying them to minions.
First, we run the command to apply the user
state to the minion, but with the following parameter:
test=True
The output of the command shows us the changes that will be applied to the minion on running the states but does not actually apply them. This is clear by the following lines:
stgdc1app02: ---------- Result: None Comment: User cyclonus set to be added ---------- Result: None Comment: User megatron set to be added Summary ------------ Succeeded: 0 Failed: 0 Not Run: 2 ------------ Total: 2
It clearly tells us that the users are set to be added, but has not been added yet. The Results
key has the value of None
showing that there was no result because nothing was actually done. Also, the following two lines show that the states were not applied:
Succeeded: 0 Not Run: 2
Next, we see how to set the test
parameter on the minion. We edited the main minion configuration file /etc/salt/minion
and uncommented the line:
test: True
This tells the minion that all states applied on it from the master will be in test mode, that is, no configuration will be actually applied. We then run the command to apply the state to the minion without the test
parameter and see that the state runs in test mode because the minion is set to test mode.
Next, we see how to override the minion's test
parameter by setting the test
parameter with the salt command. We set the test
parameter to be False
, and when the state is applied to the minion, the salt command's test
parameter overrides the test
parameter of the minion and the state gets applied successfully.
See also
- The Applying Salt states to minions recipe, in Chapter 1, Salt Architecture and Components, to learn more about applying states to minions
- The Configuring nodegroups recipe, to learn how to configure nodegroups to group similar nodes for targeting minions
- Apache Oozie Essentials
- Oracle從新手到高手
- Android 7編程入門經典:使用Android Studio 2(第4版)
- Mastering Scientific Computing with R
- Expert Android Programming
- CKA/CKAD應試教程:從Docker到Kubernetes完全攻略
- Visual C++數字圖像處理技術詳解
- 青少年學Python(第1冊)
- Web Development with MongoDB and Node(Third Edition)
- Java程序員面試筆試寶典(第2版)
- 深入理解C指針
- 區塊鏈架構之美:從比特幣、以太坊、超級賬本看區塊鏈架構設計
- 數據分析與挖掘算法:Python實戰
- Swift Essentials(Second Edition)
- jQuery Essentials