saltstack一键安装LAMP

init.sls

include:
  - lamp.pkg
  - lamp.config
  - lamp.service

pkg.sls

[root@linux-node1 /srv/salt/lamp]# cat pkg.sls 
lamp-pkg:
  pkg.installed:
    - pkgs:
      - httpd
      - php
      - mariadb
      - mariadb-server
      - php-mysql
      - php-cli
      - php-mbstring

config.sls

apache-config:
  file.managed:
    - name: /etc/httpd/conf/httpd.conf
    - source: salt://lamp/files/httpd.conf
    - user: root
    - group: root
    - mode: 644

php-config:
  file.managed:
    - name: /etc/php.ini
    - source: salt://lamp/files/php.ini
    - user: root
    - group: root
    - mode: 644

mysql-config:
  file.managed:
    - name: /etc/my.cnf
    - source: salt://lamp/files/my.cnf
    - user: root
    - group: root
    - mode: 644

service.sls

apache-service:
  service.running:
    - name: httpd
    - enable: True
    - reload: True
    - require:
      - pkg: lamp-pkg
      - file: apache-config
    - watch:
      - file: apache-config

mysql-service:
  service.running:
    - name: mariadb
    - enable: True
    - reload: True

执行

[root@linux-node1 /srv/salt/lamp]# tree /srv/salt/lamp/
/srv/salt/lamp/
├── config.sls
├── files
│   ├── httpd.conf
│   ├── my.cnf
│   └── php.ini
├── init.sls
├── pkg.sls
└── service.sls

[root@linux-node1 /srv/salt/lamp]# salt -b 50% '*' state.sls lamp.init

 

发表评论