- 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
- SoapUI Cookbook
- 移動UI設計(微課版)
- Lua程序設計(第4版)
- 從學徒到高手:汽車電路識圖、故障檢測與維修技能全圖解
- Getting Started with SQL Server 2012 Cube Development
- 匯編語言程序設計(第3版)
- FFmpeg入門詳解:音視頻原理及應用
- Android 應用案例開發大全(第3版)
- D3.js By Example
- Service Mesh實戰:基于Linkerd和Kubernetes的微服務實踐
- Python Data Science Cookbook
- uni-app跨平臺開發與應用從入門到實踐
- Ionic3與CodePush初探:支持跨平臺與熱更新的App開發技術
- WCF全面解析
- Getting Started with the Lazarus IDE