以源码安装haproxy为例,介绍sls 配置

[root@redis01-jp ~]# tree /srv/salt/
/srv/salt/
├── base
│   ├── apache
│   │   └── init.sls
│   ├── files
│   ├── nginx.sls
│   └── top.sls
├── prod
│   ├── haproxy
│   │   ├── files
│   │   │   ├── haproxy-1.7.1.tar.gz
│   │   │   └── haproxy.init
│   │   └── init.sls
│   └── pkg
│       └── init.sls
└── test
8 directories, 7 files
[root@redis01-jp ~]# cat /srv/salt/base/top.sls
base:
  'redis02-jp':
    - apache
prod:
  'redis02-jp':
    - haproxy
[root@redis01-jp ~]# cat /srv/salt/prod/pkg/init.sls
init:
  pkg.installed:
    - names:
      - gcc
      - gcc-c++
      - glibc
      - make
      - autoconf
      - openssl
      - openssl-devel
[root@redis01-jp ~]# cat /srv/salt/prod/haproxy/init.sls
include:
  - pkg
haproxy-install:
  file.managed:
    - name: /usr/local/src/haproxy-1.7.1.tar.gz
    - source: salt://haproxy/files/haproxy-1.7.1.tar.gz
    - user: root
    - group: root
    - mode: 644
  cmd.run:
    - name: cd /usr/local/src/ && tar xfz haproxy-1.7.1.tar.gz && cd haproxy-1.7.1 && make TARGET=linux26 PREFIX=/usr/local/haproxy && make install PREFIX=/usr/local/haproxy
    - unless: test -d /usr/local/haproxy
    - require:
      - pkg: init
      - file: haproxy-install
haproxy-init:
  file.managed:
    - name: /etc/init.d/haproxy
    - source: salt://haproxy/files/haproxy.init
    - user: root
    - group: root
    - mode: 755
    - require:
      - cmd: haproxy-install
  cmd.run:
    - name: chkconfig --add haproxy
    - unless: chkconfig --list |grep haproxy
    - require:
      - file: haproxy-init
net.ipv4.ip_nonlocal_bind:
  sysctl.present:
    - value: 1
haproxy-config-dir:
  file.directory:
    - name: /etc/haproxy
    - user: root
    - group: root
    - mode: 755

[root@redis01-jp ~]#