当前位置:网站首页>SaltStack State状态文件配置实例
SaltStack State状态文件配置实例
2022-06-24 18:51:00 【51CTO】
简单介绍
什么是state模块?
- 远程执行是salt的核心所在。
- 管理员可以通过执行远程执行模块,达到对minion的控制(如cmd.run “yum install -y httpd”)。但对于minion的环境或者状态控制,即你想让minion达到一个什么样的状态,用state模块更便利。 只需要描述想让salt minion达到什么状态即可,执行部分由state模块完成。
远程执行&&State模块:
- 区别:执行模块是过程式,连续调用时将执行相同的逻辑和指令;状态模块为描述性的,它们只是执行必要的工作,在minion上根据描述文件达到指定的状态。
- 所有的state模块都会遵循这个原则,只在检测到真实状态和所需状态不同的情况下才执行功能。这可以通过判断来让minion以最小的代价进入指定的状态。
State 配置文件(sls)
SLS配置文件使用 YAML 语言描述。Salt默认的sls文件的renderer是 YAML renderer,它的工作是将YAML数据格式的结构编译成为Python数据结构给Salt使用。
重要的三个规则:
- 缩进:用两个空格,不要使用 tab 键。
- 冒号:与Python的映射如下:
- 短横杠:用一个短横杠加一个空格来表示列表项(Python中的列表[])
State文件的格式:
State sls配置文件中:
- <ID Declaration>必须是独一无二的有效的Python字符串,自定义的。
- <State Module>.<Function>与远程执行命令采用相同格式,但是具体支持的模块和函数与远程执行的模块和函数有差异,可分别通过sys.list_state_modules、sys.list_state_functions 查看,远程对应的则是sys.list_modules、sys.list_functions。
- 最后是函数参数,首个函数参数通常是name,然后是状态所需的其他参数。具体用法可参考sys.state_doc.
实践案例
- 配置windows防火墙
conf-firewall.sls
实践效果:
执行前,私有网络和共有网络防火墙为开启状态;state执行后,变成关闭状态。
- 管理windows服务
conf-services.sls
实践效果:
执行前:

执行后: 两个服务均被停止运行,且w32Time被设置为开机自启动。

- 执行ps脚本【以服务器封网为例】
conf-gateway.sls
执行前:

执行后: 缺省网关被删除。

- 启用RDP远程桌面
conf-rdp.sls
实践效果:

边栏推荐
- Introduction to alos satellite
- 特尔携手微软发挥边云协同势能,推动AI规模化部署
- 解读HarmonyOS 应用与服务生态
- Application DDoS attack principle and defense method
- Remote sensing Forum
- Introduction and download tutorial of administrative division vector data
- What type of datetime in the CDC SQL table should be replaced
- Freeswitch使用originate转dialplan
- 【计算讲谈社】第三讲:如何提出关键问题?
- 干货 | 新手经常忽略的嵌入式基础知识点,你都掌握了吗?
猜你喜欢

「碎语杂记」这事儿不安全

Why is nodejs so fast?

Generate the last login user account report of the computer through SCCM SQL

Why useevent is not good enough

试驾 Citus 11.0 beta(官方博客)

Do you have all the basic embedded knowledge points that novices often ignore?

应用实践 | 海量数据,秒级分析!Flink+Doris 构建实时数仓方案

Kubernetes集群部署

Starring develops httpjson access point + Database

The sharp sword of API management -- eolink
随机推荐
Module V
cdc+mysql connector从维表中join的日期时间字段会被+8:00,请问阿里云托管的
使用阿里云RDS for SQL Server性能洞察优化数据库负载-初识性能洞察
模块五
Fabric ledger data block structure analysis (I): how to analyze the smart contract transaction data in the ledger
初步学习Nuxt3
At present, only CDC monitors Mysql to get the data of new columns. Sqlserver can't, can it
Introduction and download tutorial of two types of soil data
Tkde2022: Dialogue recommendation system based on knowledge enhanced sampling
「碎语杂记」这事儿不安全
Why are life science enterprises on the cloud in succession?
Volcano成Spark默认batch调度器
Do you have all the basic embedded knowledge points that novices often ignore?
Necessary fault handling system for enterprise network administrator
一文详解|Go 分布式链路追踪实现原理
Multi segment curve temperature control FB (SCL program) of PLC function block series
[computer talk club] Lecture 3: how to raise key issues?
网络安全审查办公室对知网启动网络安全审查
特尔携手微软发挥边云协同势能,推动AI规模化部署
Fabric 账本数据块结构解析(一):如何解析账本中的智能合约交易数据