- Salt Cookbook
- Anirban Saha
- 691字
- 2021-07-16 13:21:58
Using execution modules
Modules are the basic foundations of configuration management in Salt. Using Salt modules, we can configure systems from Salt state files, as well as from the command line. In this chapter, you will learn about how to use Salt modules from the command line.
How to do it...
Configure a minion in the staging environment. We will call it stgdc1log01
.
- Run the following command to list all the
cron
entries for theroot
user on the minion:[root@salt-master ~]# salt 'stgdc1log01' cron.list_tab root stgdc1log01: ---------- crons: env: pre: special:
- Run the following command to add a new
cron
entry for theroot
user:[root@salt-master ~]# salt 'stgdc1log01' cron.set_job root '00' '12' '*' \ '*' '*' 'find /var/log/ -mtime +30 -exec rm - rf {} \;' stgdc1log01: new
- Run the following command to verify that the new
cron
was added properly:[root@salt-master ~]# salt 'stgdc1log01' cron.list_tab root stgdc1log01: ---------- crons: |_ ---------- cmd: find /var/log/ -mtime +30 -exec rm -rf {} \; comment: None daymonth: * dayweek: * hour: 12 identifier: None minute: 0 month: * env: pre: special:
- Run the following command to remove the
cron
entry:[root@salt-master ~]# salt 'stgdc1log01' cron.rm_job root 'find /var/log/ -mtime +30 -exec rm -rf {} \;' stgdc1log01: removed
- Run the following command to verify that it was removed:
[root@salt-master ~]# salt 'stgdc1log01' cron.list_tab root stgdc1log01: ---------- crons: env: pre: special:
How it works...
Salt modules are the entity that contains the parameters and information required to perform necessary configurations on minions. In Salt, modules are of two types: state and execution modules. In this recipe, you will learn about the details of execution modules and methods by which to use them.
Execution modules are the ones that can be used from the command line of the Salt master using the salt-binary
command. A complete list of all the available Salt execution modules can be found at http://docs.saltstack.com/en/latest/ref/modules/all. The number of execution modules available in Salt is generally more than the number of state modules. Both the types of modules are extremely helpful in configuring minions.
The general structure of running an execution module consists of the salt
command, the target minion using the various targeting methods, the module name along with the function, and the data being passed to the minion.
In this recipe, we made use of the cron
execution module to perform some configuration related to crontab
scheduling on the minion.
First, we listed the available crontab
configurations for the root
user:
[root@salt-master ~]# salt 'stgdc1log01' cron.list_tab root
The first word in the command is salt
, which is the salt
command. Next, we specified the minion to target for this action; this targeting can be performed by using the various methods demonstrated in Chapter 2, Writing Advanced Salt Configurations. The next entity in the command is what we are interested in, that is, cron.list_tab
, which is our execution module implementation. Here, cron
is the name of the module and list_tab
is a function under the module. There are multiple functions available for all modules that can be looked up from the list of modules in the preceding link. We have then mentioned the user for which we want to retrieve the crontab
list.
In the next few commands, we added a new cron
entry for the root user, verified that it got added, and then removed the entry and again verified it. To carry out these tasks, we used a few more functions of the cron
module, such as set_job
and rm_job
, with the proper number of data fields, which need to be passed for each of them. The number of fields of data that needed to be passed differ as per the function being used and are very well documented in the preceding link.
The list of execution modules in Salt is quite large and supports a wide range of tasks that can be performed on the minions. We will look at some of the most important of them in later chapters.
See also
- The Targeting minions recipe in Chapter 2, Writing Advanced Salt Configurations, to learn about how to target minions
- The Using state modules recipe, to learn how to use state modules
- The Complete Rust Programming Reference Guide
- Mobile Web Performance Optimization
- 大學(xué)計算機應(yīng)用基礎(chǔ)實踐教程
- Learning Real-time Processing with Spark Streaming
- Leap Motion Development Essentials
- Hands-On Data Structures and Algorithms with JavaScript
- 概率成形編碼調(diào)制技術(shù)理論及應(yīng)用
- HDInsight Essentials(Second Edition)
- Cocos2d-x學(xué)習(xí)筆記:完全掌握Lua API與游戲項目開發(fā) (未來書庫)
- Flutter跨平臺開發(fā)入門與實戰(zhàn)
- Python項目實戰(zhàn)從入門到精通
- ExtJS Web應(yīng)用程序開發(fā)指南第2版
- Building Dynamics CRM 2015 Dashboards with Power BI
- Data Science Algorithms in a Week
- 嵌入式C編程實戰(zhàn)