justin 齐齐
生命在于折腾

 

 远程执行  salt '*' state.sls apache

 

'*':代表所有主机

state.sls :是一个模块

apache : 状态 ,表示需要部署的内容,后缀.sls

  

 

 

YAML:三板斧

 

1、 缩进   (2个空格,不能使用Tab)

2、 冒号 key: value (注意key后面需要有空格)

3、 短横线 – list1   - list2  可以写多个

 

 

缩进和冒号表示层级关系:

冒号表示key: value   表示层级关系
短横线 – list      列表,后面都有空格
/etc/salt/master配置文件也是YAML语法
表示协议的肯定没有空格


ps -aux|grep salt

 

 

Master配置 测试安装

案例一、

# vim /etc/salt/master


 

base 基础环境必须有

file_roots  配置项

- /srv/salt/ 列表,可以写多个路径

 

 




因为里面定义了.sls存放的路径,需要我们创建

[root@Master ~]# mkdir /srv/salt -p   #创建目录,用于存放sls


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

apache-service:
  service.running:
    - name: httpd
    - enable: True
    - reload: True

  

修改完配置文件需要重启

systemctl restart salt-master





参数介绍:
apache-install:  定义的ID
  pkg.installed:  pkg是一个模块是一个状态后面是模块的方法
    - names:  方法的一个参数
      - httpd
      - httpd-devel安装包名称
apache-servic:
  service.running:   模块  方法 running运行
    - name: httpd   运行服务的名称
- enable: True   开机自动启动

  

执行状态

[root@01 salt]# ls
apache.sls
[root@01 salt]# pwd
/srv/salt
[root@01 salt]# salt '*' status.sls apache


Master: ---------- ID: apache-install Function: pkg.installed Name: httpd Result: True Comment: The following packages were installed/updated: httpd Started: 00:55:59.517437 Duration: 32821.597 ms Changes: ---------- httpd: ---------- new: 2.4.6-45.el7.centos old: httpd-tools: ---------- new: 2.4.6-45.el7.centos old: ---------- ID: apache-install Function: pkg.installed Name: httpd-devel Result: True Comment: The following packages were installed/updated: httpd-devel Started: 00:56:32.347203 Duration: 35405.626 ms Changes: ---------- apr-devel: ---------- new: 1.4.8-3.el7 old: apr-util-devel: ---------- new: 1.5.2-6.el7 old: cyrus-sasl: ---------- new: 2.1.26-20.el7_2 old: cyrus-sasl-devel: ---------- new: 2.1.26-20.el7_2 old: cyrus-sasl-lib: ---------- new: 2.1.26-20.el7_2 old: 2.1.26-17.el7 expat: ---------- new: 2.1.0-10.el7_3 old: 2.1.0-8.el7 expat-devel: ---------- new: 2.1.0-10.el7_3 old: httpd-devel: ---------- new: 2.4.6-45.el7.centos old: libdb: ---------- new: 5.3.21-19.el7 old: 5.3.21-17.el7_0.1 libdb-devel: ---------- new: 5.3.21-19.el7 old: libdb-utils: ---------- new: 5.3.21-19.el7 old: 5.3.21-17.el7_0.1 openldap: ---------- new: 2.4.40-13.el7 old: 2.4.39-6.el7 openldap-devel: ---------- new: 2.4.40-13.el7 old: ---------- ID: apache-servic Function: service.running Name: httpd Result: True Comment: Service httpd has been enabled, and is running Started: 00:57:07.787998 Duration: 2090.702 ms Changes: ---------- httpd: True Summary ------------ Succeeded: 3 (changed=3) Failed: 0 ------------ Total states run: 3

  

 

运行地点:

cat /var/cache/salt/minion/files/base/web/apache.sls


案例2

高级配置top调用apache.sls

 


 


[root@Master web]# cat  /srv/salt/top.sls
base:
  'Minion1':    -->表示minion主机名称
    - web.apache
  'Minion2': 
    - web.apache

  


执行命令:

salt '*' state.highstate  

highstate: 是state模块中的方法

[root@01 salt]# salt '*' state.highstate
www.wawa8888.com:
----------
          ID: apache-install
    Function: pkg.installed
        Name: httpd
      Result: True
     Comment: Package httpd is already installed
     Started: 10:58:04.124771
    Duration: 837.654 ms
     Changes:   
----------
          ID: apache-install
    Function: pkg.installed
        Name: httpd-devel
      Result: True
     Comment: Package httpd-devel is already installed
     Started: 10:58:04.962555
    Duration: 0.365 ms
     Changes:   
----------
          ID: apache-service
    Function: service.running
        Name: httpd
      Result: True
     Comment: Service httpd is already enabled, and is running
     Started: 10:58:04.963307
    Duration: 71.43 ms
     Changes:   
              ----------

  返回的结果是执行的结果


posted on 2017-05-03 10:24  justin01  阅读(248)  评论(0编辑  收藏  举报