Salt : Salt State File を利用する#22016/10/08 |
|
Top File と呼ばれる top.sls ファイルを起点に、ツリー状に State ファイルを配置する State Tree の構成例です。
|
|
| [1] | 定義したルートディレクトリ直下に top.sls を配置し、そこからツリー状にファイルを配置して設定します。 |
|
[root@dlp ~]#
vi /srv/salt/top.sls base: # ターゲットノードを定義 '*': # State ファイルの名称を定義 (SLSファイルの拡張子を除いた部分) # State ファイルは複数行を指定して設定可能 - default # 例として httpd/PHP/MariaDB をインストールして起動する State
webserver:
pkg.installed:
- pkgs:
- httpd
- php
- php-mbstring
- php-pear
- mariadb-server
/var/www/html/index.php:
file:
- managed
- source: salt://httpd/index.php
- require:
- pkg: webserver
# パスワード設定等の初期設定スクリプト
/tmp/setup.sql:
file:
- managed
- source: salt://httpd/setup.sql
enable_httpd:
service.running:
- name: httpd
- enable: True
- require:
- pkg: webserver
enable_mariadb:
service.running:
- name: mariadb
- enable: True
- require:
- pkg: webserver
setup_mariadb:
cmd.run:
- name: '/bin/mysql -u root < /tmp/setup.sql'
- require:
- service: enable_mariadb
# Firewalld 稼働中の場合はサービス許可設定
{% set fw_status = salt['service.status']('firewalld') %}
{% if fw_status %}
setup_fw:
cmd.run:
- names:
- '/bin/firewall-cmd --add-service={http,https,mysql}'
- '/bin/firewall-cmd --add-service={http,https,mysql} --permanent'
{% endif %}
<?php print "Salt State Test Page"; ?>
set password for root@localhost=password('password');
set password for root@'127.0.0.1'=password('password');
delete from mysql.user where user='';
delete from mysql.user where password='';
drop database test;
# state.apply で適用 [root@dlp ~]# salt "*" state.apply
node01.srv.world:
----------
cmd_|-setup_fw_|-/bin/firewall-cmd --add-service={http,https,mysql} --permanent_|-run:
----------
__run_num__:
7
changes:
.....
.....
name:
mariadb
result:
True
start_time:
19:56:52.911517
# 確認 [root@dlp ~]# salt "node01.srv.world" cmd.run 'systemctl status httpd'
[root@dlp ~]# salt "node02.srv.world" cmd.run 'systemctl status httpd'
node01.srv.world:
* httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2016-10-17 10:56:52 JST; 2min 16s ago
.....
.....
[root@dlp ~]# salt "node01.srv.world" cmd.run 'systemctl status httpd'
[root@dlp ~]# salt "node02.srv.world" cmd.run 'systemctl status httpd'
node01.srv.world:
* mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2016-10-17 10:56:57 JST; 2min 24s ago
.....
.....
[root@dlp ~]# salt "node01.srv.world" cmd.run 'mysql -u root -ppassword -e "show databases;"'
[root@dlp ~]# salt "node02.srv.world" cmd.run 'systemctl status httpd'
node01.srv.world:
Database
information_schema
mysql
performance_schema
[root@dlp ~]# curl http://node01.srv.world/index.php Salt State Test Page |
| Sponsored Link |
|
|