OSSのサーバ構築自動化ツール、4製品徹底検証 2016年版実際に検証済み!OSS徹底比較(3)サーバ構築自動化【前編】(9/9 ページ)

» 2016年06月23日 05時00分 公開
[森元敏雄,TIS]
前のページへ 1|2|3|4|5|6|7|8|9       

Sample playbookを使ってみる

 WordPressのインストールは、GitHubの「ansible-examples」上で公開されているplaybookを利用して行うこともできる。このplaybookを利用してインストールを行ってみた。6ページのAnsibleのインストール手順「5.ansibleのログ出力フォルダとlogファイルの作成」からの続きとなる。その手順は以下となる。

1.Gitのインストール

$ sudo yum install -y git

2.ansible-examplesのplaybookのダウンロード

$ mkdir ~/playbook
$ cd ~/playbook
$ git clone https://github.com/ansible/ansible-examples
Cloning into 'ansible-examples'...
remote: Counting objects: 2231, done.
remote: Total 2231 (delta 0), reused 0 (delta 0), pack-reused 2231
Receiving objects: 100% (2231/2231), 3.81 MiB | 1.63 MiB/s, done.
Resolving deltas: 100% (638/638), done.

3.ansible-examples/wordpress-nginx_rhel7のplaybookの確認

 今回インストールに使用するansible-examples/wordpress-nginx_rhel7のフォルダおよびファイルの構成は以下となる。前述の構築例とは、Apache 2ではなくNginxを使用している点が大きく異なる。

# tree ./playbook/ansible-examples/wordpress-nginx_rhel7
./playbook/ansible-examples/wordpress-nginx_rhel7
├── LICENSE.md
├── README.md
├── group_vars
│   └── all
├── hosts.example
├── roles
│   ├── common
│   │   ├── files
│   │   │   ├── RPM-GPG-KEY-EPEL-7
│   │   │   ├── RPM-GPG-KEY-NGINX
│   │   │   ├── epel.repo
│   │   │   └── nginx.repo
│   │   └── tasks
│   │       └── main.yml
│   ├── mariadb
│   │   ├── handlers
│   │   │   └── main.yml
│   │   ├── tasks
│   │   │   └── main.yml
│   │   └── templates
│   │       └── my.cnf.j2
│   ├── nginx
│   │   ├── handlers
│   │   │   └── main.yml
│   │   ├── tasks
│   │   │   └── main.yml
│   │   └── templates
│   │       └── default.conf
│   ├── php-fpm
│   │   ├── handlers
│   │   │   └── main.yml
│   │   ├── tasks
│   │   │   └── main.yml
│   │   └── templates
│   │       └── wordpress.conf
│   └── wordpress
│       ├── tasks
│       │   └── main.yml
│       └── templates
│           └── wp-config.php
└── site.yml

4.group_vars/allをコピーしてhost_vars/allを作成

$ cp -rp ~/playbook/ansible-examples/wordpress-nginx_rhel7/group_vars ~/playbook/ansible-examples/wordpress-nginx_rhel7/host_vars

5.host_vars/allをコピーしてnode専用のパラメータ設定ファイルを作成

$ cp -p ~/playbook/ansible-examples/wordpress-nginx_rhel7/host_vars/all ~/playbook/ansible-examples/wordpress-nginx_rhel7/host_vars/tissvv096

6.WordPressの最新バージョンをダウンロードし、コピーしてチェックサム(sha256sum)を算出

$ curl -O https://wordpress.org/wordpress-4.5.2.tar.gz
$ sha256sum wordpress-4.5.2.tar.gz
1a4d9f05142701e72413609cc30029f66af0f3b29d4ff051e888f48026d20ac9

7.node専用のパラメータ設定ファイルを編集

vi ~/playbook/ansible-examples/wordpress-nginx_rhel7/host_vars/tissvv096
---
# Variables listed here are applicable to all host groups
wp_version: 4.5.2
wp_sha256sum: 1a4d9f05142701e72413609cc30029f66af0f3b29d4ff051e888f48026d20ac9
# MySQL settings
mysqlservice: mariadb
mysql_port: 3306
# These are the WordPress database settings
wp_db_name: WordPress
wp_db_user: wp_admin
wp_db_password: HB-F1XDJ
# This is used for the nginx server configuration, but access to the
# WordPress site is not restricted by a named host.
nginx_port: 80
server_hostname: tissvv096
# Disable All Updates
# By default automatic updates are enabled, set this value to true to disable all automatic updates
auto_up_disable: false
#Define Core Update Level
# true  = Development, minor, and major updates are all enabled
# false = Development, minor, and major updates are all disabled
# minor = Minor updates are enabled, development, and major updates are disabled
core_update_level: true

8.node専用のパラメータ設定ファイルを編集

$ vi ./playbook/ansible-examples/wordpress-nginx_rhel7/hosts
[wordpress-server]
tissvv096

9.処理対象のhostsグループ、実行ユーザ、設定に使用するroleを定義するsite.yamlファイル

$ vi ~/playbook/ansible-examples/wordpress-nginx_rhel7/site.yml
- name: Install WordPress, MariaDB, Nginx, and PHP-FPM
  hosts: wordpress-server
  remote_user: maintain
  sudo: yes
  roles:
    - common
    - mariadb
    - nginx
    - php-fpm
    - wordpress

10.playbookの構文チェックを実施

$ ansible-playbook ~/playbook/ansible-examples/wordpress-nginx_rhel7/site.yml -i ~/playbook/ansible-examples/wordpress-nginx_rhel7/hosts --key-file=~/.ssh/id_rsa.pem --syntax-check
playbook: /root/playbook/ansible-examples/wordpress-nginx_rhel7/site.yml

11.playbookの実行

$ ansible-playbook ~/playbook/ansible-examples/wordpress-nginx_rhel7/site.yml -i ~/playbook/ansible-examples/wordpress-nginx_rhel7/hosts --key-file=~/.ssh/id_rsa.pem

 以上の作業で構築は完了で、あとはブラウザからの初期設定となる。

 ansible-examples内には、WordPress以外にもMongoDBやJBoss、Tomcat、LAMP(Linux+Apache+MySQL+PHP/Perl/Python)のplaybookのサンプルが格納されている。さらに、language_featuresフォルダには、各種プロダクトの構築サンプルとなるyamlファイルが多数格納されている。playbook作成前にはサンプルも参照し、有効に活用したい。

 後編と4製品の比較コメントは明日、2016年6月24日に公開する。

著者プロフィール

森元 敏雄(もりもと としお)

TIS株式会社

R&D部門である戦略技術センター所属。

金融系の大規模システム開発やプライベートクラウド開発環境の構築・運用の経験を生かし、OSS製品を中心とした技術調査・検証を担当。


前のページへ 1|2|3|4|5|6|7|8|9       

Copyright © ITmedia, Inc. All Rights Reserved.

RSSについて

アイティメディアIDについて

メールマガジン登録

@ITのメールマガジンは、 もちろん、すべて無料です。ぜひメールマガジンをご購読ください。