saltstack配置sls文件下发

2023年 7月 15日 59.7k 0

在上篇文章中的返回结果是已经安装过的!通过salt在尝试安装sl,返回结果如下:

[root@master init]# salt 'minios.10.0.0.8.com'  state.sls init.pkg
minios.10.0.0.8.com:
----------
          ID: pkg.init
    Function: pkg.installed
        Name: sl
      Result: True
     Comment: The following packages were installed/updated: sl
     Started: 07:05:37.645283
    Duration: 145585.54 ms
     Changes:   
              ----------
              sl:
                  ----------
                  new:
                      5.02-1.el6
                  old:

Summary
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
[root@master init]# 

saltstack配置文件下发创建配置文件的模块!批量修改/etc/security/limits.conf文件~

    [root@master init]# vim /etc/salt/status/init/conf.sls         
conf-config:----------------------------------->命名
  file.managed:-------------------------------->file状态模块:managed管理
    - name: /etc/security/limits.conf---------->name:被管理文件的路径
    - source: salt://init/files/limits.conf---->source:salt://limits.conf在master的文件路径
    - user: root------------------------------->文件用户
    - group: root------------------------------>组
    - mode: 644-------------------------------->权限

当创建完config.sls后需要在top.sls中写入init.conf,才能够调用!

[root@master status]# vim /etc/salt/status/top.sls 
base:

  'minios.10.0.0.8.com':
    - init.pkg
    - init.conf

创建files目录

[root@master init]# mkdir files
[root@master init]# pwd
/etc/salt/status/init
[root@master init]# 

/etc/security/limits.conflimits.conf复制到/etc/salt/status/init/files

[root@master init]# cp /etc/security/limits.conf /etc/salt/status/init/files/

修改/etc/salt/status/init/files/下的limits.conf模板,打开两个参数,如下:

[root@master init]# vim /etc/salt/status/init/files/limits.conf 
*               soft    core            0
*               hard    rss             10000

没改之前,在minion查看

[root@minion ~]# cat /etc/security/limits.conf |grep 10000
#*               hard    rss             10000
[root@minion ~]# 


我们在master上执行state.highstate,在执行过程中,都会检查pkg和conf

[root@master init]# salt 'minios.10.0.0.8.com' state.highstate 
minios.10.0.0.8.com:
----------
          ID: pkg.init
    Function: pkg.installed
        Name: sl
      Result: True
     Comment: Package sl is already installed.
     Started: 07:34:41.304171
    Duration: 978.561 ms
     Changes:   
----------
          ID: conf-config
    Function: file.managed
        Name: /etc/security/limits.conf
      Result: True
     Comment: File /etc/security/limits.conf updated
     Started: 07:34:42.339015
    Duration: 27.806 ms
     Changes:   
              ----------
              diff:
                  ---  
                  +++  
                  @@ -39,8 +39,8 @@
                   #                 
                   #
                   
                  -#*               soft    core            0
                  -#*               hard    rss             10000
                  +*               soft    core            0
                  +*               hard    rss             10000
                   #@student        hard    nproc           20
                   #@faculty        soft    nproc           20
                   #@faculty        hard    nproc           50

Summary
------------
Succeeded: 2 (changed=1)
Failed:    0
------------
Total states run:     2
[root@master init]# 

在minion上查看结果

[root@minion ~]# cat /etc/security/limits.conf |grep 10000
*               hard    rss             10000
[root@minion ~]#

saltstack配置sls文件下发-1

相关文章

对接alertmanager创建钉钉卡片(1)
手把手教你搭建OpenFalcon监控系统
无需任何魔法即可使用 Ansible 的神奇变量“hostvars”
openobseve HA本地单集群模式
基于k8s上loggie/vector/openobserve日志收集
openobseve单节点和查询语法

发布评论