saltstack lamp自动化案例实战
cd /src/salt/lamp
vim apache.sls
apache-install:
pkg.installed:
- name: httpd
apache-config:
file.managed:
- name: /etc/httpd/conf/httpd.conf
- source: salt://lamp/files/httpd.conf #这里的salt://指当前环境base里的 /srv/salt
- user: root
- group: root
- mode: 644
apache-service:
service.running:
- name: httpd
- enable: True
cd lamp/files/
cp /etc/httpd/conf/httpd.conf .
vim php.sls
php-install:
pkg.installed:
- pkgs:
- php
- php-mysql
- php-cli
- php-pdo
- php-common
php-config:
file.managed:
- name: /etc/php.ini
- source: salt://lamp/files/php.ini
- user: root
- group: root
- mode: 644
这个需要把php.ini放在相应的目录下
状态之间的关系:
sls文件可以include其他的sls文件,示例:(在apache.sls里面include其他的sls)
include:
- lamp.php
vim mysql.sls
mysql-install:
pkg.installed:
- pkgs:
- mariadb
- mariadb-server
mysql-config:
file.managed:
- name: /etc/my.cnf
- source: salt://lamp/files/my.cnf
- user:root
- group: root
- mode:644
msyql-service:
service.running:
- name: mariadb
- enable: True
上面配置文件就已经完成
接着就是在top.sls里面指定安装就可以了
base:
'linux-node1.example.com':
- lamp.mysql
'linux-node2.example.com':
- lamp.apache