saltstack配置管理

创建一个base目录(编辑配置文件不要使用TAB键

vim /etc/salt/master


mkdir /srv/salt -p
改配置文件后需要重启服务
[root@saltstack-server ~]# systemctl stop salt-master.service
[root@saltstack-server ~]# systemctl start salt-master.service

state.highstate:这个是全局的所有环境,以及所有状态都生效。它会读取每一个环境的top.sls,并且对所有sls都生效。

state.sls默认的运行环境是base环境,但是它并不读取top.sls(top.sls定义了运行环境以及需要运行的sls)。

state.sls 模块使用
salt 'Saltstack-server' state.sls apache

[root@saltstack-server salt]# cat apache.sls 
apache-install:
  pkg.installed:
    - names:
      - httpd
      - httpd-devel


apache-service:
  service.running:
      - name: httpd
      - enable: True
      - reload: True
执行之后的结果
[root@saltstack-server salt]# salt 'Saltstack-server' state.sls apache
Saltstack-server:
----------
          ID: apache-install
    Function: pkg.installed
        Name: httpd
      Result: True
     Comment: Package httpd is already installed.
     Started: 17:08:22.356030
    Duration: 398.079 ms
     Changes:   
----------
          ID: apache-install
    Function: pkg.installed
        Name: httpd-devel
      Result: True
     Comment: Package httpd-devel is already installed.
     Started: 17:08:22.754226
    Duration: 0.336 ms
     Changes:   
----------
          ID: apache-service
    Function: service.running
        Name: httpd
      Result: True
     Comment: Service httpd is already enabled, and is in the desired state
     Started: 17:08:22.754888
    Duration: 203.497 ms
     Changes:   
Summary
------------
Succeeded: 3
Failed:    0
------------
Total states run:     3

state.highstate模块是使用

[root@saltstack-server salt]# cat top.sls 
base:
  '*' :
      - apache

执行结果

[root@saltstack-server salt]# salt '*' state.highstate
zabbix-server:
----------
          ID: apache-install
    Function: pkg.installed
        Name: httpd
      Result: True
     Comment: Package httpd is already installed.
     Started: 17:23:45.054951
    Duration: 520.274 ms
     Changes:   
----------
          ID: apache-install
    Function: pkg.installed
        Name: httpd-devel
      Result: True
     Comment: Package httpd-devel is already installed.
     Started: 17:23:45.575331
    Duration: 0.255 ms
     Changes:   
----------
          ID: apache-service
    Function: service.running
        Name: httpd
      Result: True
     Comment: Service httpd is already enabled, and is in the desired state
     Started: 17:23:45.575946
    Duration: 272.514 ms
     Changes:   
Summary
------------
Succeeded: 3
Failed:    0
------------
Total states run:     3

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiegh2014/article/details/52142326
个人分类: 自动化运维
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭