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

» 2016年06月23日 05時00分 公開
[森元敏雄,TIS]

Ansibleのプロフィール

 Ansible旧Ansible社が開発した製品で、2012年4月に最初のStable版の0.3がリリースされている。ライセンスはGPL V3で、2016年4月現在、最新の安定バージョンは2016年2月20日にリリースされた2.0.2となっている。開発を行っていたAnsible社は2015年8月16日にレッドハットに買収され、Ansibleもレッドハットの製品の一部となっている。

Ansibleのインストール

 今回の検証では、CentOS 7.2のyumコマンドでインストールが行えるVer 2.0.1をインストールしている。AnsibleはPythonで開発されおり、サーバの設定を行うplaybookはyaml形式のファイルを使用している。Ansible本体のインストールやplaybookの作成方法は、公式のドキュメントサイトで詳しく記載されている。インストールの手順は以下の通りだ。

1.インストール済みパッケージの更新

$ sudo yum update -y

2.epelリポジトリのインストール

$ sudo yum install -y epel-release.noarch

3.Ansibleのインストール

$ sudo yum install -y ansible

4.Ansibleの設定ファイルの編集

 ログを/var/log/ansible/ansible.logに出力する設定および、deprecation_warningsの出力を無効化する設定を行う。

$ sudo vi /etc/ansible/ansible.cfg
# logging is off by default unless this path is defined
# if so defined, consider logrotate
#log_path = /var/log/ansible.log
log_path = /var/log/ansible/ansible.log
(中略)
# by default (as of 1.4), Ansible may display deprecation warnings for language
# features that should no longer be used and will be removed in future versions.
# to disable these warnings, set the following value to False:
#deprecation_warnings = True
deprecation_warnings = False

5.Ansibleのログ出力フォルダとlogファイルの作成

$ sudo mkdir /var/log/ansible
$ sudo touch /var/log/ansible/ansible.log
$ sudo chmod -R a+rw /var/log/ansible

6.Ansibleのplaybookフォルダの作成とnodeのホスト名の登録

$ mkdir -p  ~/playbook/wordpress_sample	
$ vi ~/playbook/wordpress_sample/hosts
[wordpress-server]
tissvv096

7.Ansibleの接続テスト

 接続はホスト名ではなく、hostsファイルに登録されたグループ名になる。グループ内にnodeサーバが複数存在する場合は、全てのサーバに順番に処理が行われる。このテストで同時に.ssh/known_hostsに登録されるため、接続時の確認が出力されなくなる。

$ ansible wordpress-server -a "uname -a" -i ~/playbook/wordpress_sample/hosts --key-file=~/.ssh/id_rsa.pem
The authenticity of host 'tissvv096 (10.255.202.96)' can't be established.
ECDSA key fingerprint is 4f:fd:40:9b:ea:98:80:cf:b4:1a:de:6b:69:3e:79:34.
Are you sure you want to continue connecting (yes/no)? yes
tissvv096 | SUCCESS | rc=0 >>
Linux tissvv096 3.10.0-327.13.1.el7.x86_64 #1 SMP Thu Mar 31 16:04:38 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

 node側には特に実施が必要な作業はない。これでインストールと基本的な設定の確認が完了となり、サーバの構築と設定を行うplaybookを作成、実行することが可能となる。

Copyright © ITmedia, Inc. All Rights Reserved.

RSSについて

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

メールマガジン登録

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