码迷,mamicode.com
首页 > Web开发 > 详细

saltstack自动部署apache实例

时间:2015-08-02 06:28:08      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:saltstack httpd


1、配置pillar的top.sls:


base:
  nova:
    - match: nodegroup
    - nova
  neutron:
    - match: nodegroup
    - neutron



2、pillar的nova和neutron的配置:


apache:
  name: httpd
  ip: 172.16.171.120
  root: /var/www/neutron
apache:
  name: httpd
  ip: 172.16.171.110
  root: /var/www/nova



3、配置state的top.sls:


base:
  ‘*‘:
    - apache.start
    - apache.stop



4、配置apache.start:


apache.start:
  pkg.installed:
    - name: {{ pillar[‘apache‘][‘name‘] }}
  service.running:
    - name: {{ pillar[‘apache‘][‘name‘] }}
    - watch:
      - pkg: {{ pillar[‘apache‘][‘name‘] }}
      - file: /etc/httpd/conf/httpd.conf
      - user: apache
  user.present:
    - name: apache
    - shell: /sbin/nologin
    - home: {{ pillar[‘apache‘][‘root‘] }}
    - require:
      - group: apache
  group.present:
    - name: apache
    - require:
      - pkg: {{ pillar[‘apache‘][‘name‘] }}
  file.managed:
      - name: /etc/httpd/conf/httpd.conf
      - source: salt://apache/httpd.conf
      - user: root
      - group: root
      - mode: 644
      - template: jinja                              注:必须指定,否则httpd.conf中的pillar变量无法替换。
{{ pillar[‘apache‘][‘root‘] }}/new:
  file.directory:
    - file_mode: 640
    - dir_mode: 750

{{ pillar[‘apache‘][‘root‘] }}/test/process.sh:
  file.managed:
    - source: salt://apache/process.sh
    - makedirs: True




4、配置apache.stop:


apache.stop:
  pkg.removed:
    - name: {{ pillar[‘apache‘][‘name‘] }}
    - require:
      - service: {{ pillar[‘apache‘][‘name‘] }}
  service.dead:
    - name: {{ pillar[‘apache‘][‘name‘] }}
  user.absent:
    - name: apache
    - purge: True
    - require:
      - pkg: {{ pillar[‘apache‘][‘name‘] }}



5、在httpd.conf配置文件中指定:


Listen {{ pillar[‘apache‘][‘ip‘] }}:80

DocumentRoot {{ pillar[‘apache‘][‘root‘] }}



6、如果在httpd.conf中不指定pillar变量,直接指定自定义变量名,即如下:


Listen {{ addr }}:80

DocumentRoot {{ dir }}



7、即可在apache.start指定defaults或context,具体如下:


apache.start:
  pkg.installed:
    - name: {{ pillar[‘apache‘][‘name‘] }}
  service.running:
    - name: {{ pillar[‘apache‘][‘name‘] }}
    - watch:
      - pkg: {{ pillar[‘apache‘][‘name‘] }}
      - file: /etc/httpd/conf/httpd.conf
      - user: apache
  user.present:
    - name: apache
    - shell: /sbin/nologin
    - home: {{ pillar[‘apache‘][‘root‘] }}
    - require:
      - group: apache
  group.present:
    - name: apache
    - require:
      - pkg: {{ pillar[‘apache‘][‘name‘] }}
  file.managed:
      - name: /etc/httpd/conf/httpd.conf
      - source: salt://apache/httpd.conf
      - user: root
      - group: root
      - mode: 644
      - template: jinja
      - context:
          addr: {{ pillar[‘apache‘][‘ip‘] }}
          dir: {{ pillar[‘apache‘][‘root‘] }}



本文出自 “秋天的童话” 博客,请务必保留此出处http://wushank.blog.51cto.com/3489095/1680918

saltstack自动部署apache实例

标签:saltstack httpd

原文地址:http://wushank.blog.51cto.com/3489095/1680918

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!