-
Notifications
You must be signed in to change notification settings - Fork 7
Get Started
SHIFT wareを一通り体験してみましょう。
ここではSHIFT wareを利用してターゲットマシン(Linux/Windows)のOS設定を行うシナリオを取り上げます。

このシナリオでは同一のネットワークに接続された4台のマシンを利用します。
| マシン名 | 役割 | 備考 |
|---|---|---|
| ツール実行PC | Excel2YAMLツールを実行するマシン | OSはWindows7 Microsoft Excelを事前導入済 |
| コントロールマシン | SHIFT wareを実行するマシン | OSはCentOS7.1 IPアドレスは192.168.151.10 |
| ターゲットマシン1 | OS設定を行いたいマシン | OSはCentOS7.1 IPアドレスは192.168.151.11 |
| ターゲットマシン2 | OS設定を行いたいマシン | OSはWindowsServer2012R2 IPアドレスは192.168.151.12 |
コントロールマシンおよびターゲットマシンはOSのインストールとIPアドレスの設定を行い、コントロールマシンからターゲットマシンにスーパーユーザー(rootもしくはAdministrator)でアクセスできるようにしておいてください。
ターミナルソフトを使ってコントロールマシンへrootユーザで接続します。 また、インターネットへの接続にプロキシ設定が必要な環境のみ、環境変数PROXYにプロキシサーバの設定を行います。
[root@control ~]# pwd
/root
[root@control ~]# export PROXY=http://(プロキシサーバアドレス):(ポート番号)
セットアップ用スクリプトを適当なディレクトリ(ここでは/root)にコピーして実行します。
[root@control ~]# curl -o control_setup.sh https://raw.githubusercontent.com/wiki/SHIFT-ware/shift_ware/images/control_setup.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1809 100 1809 0 0 14321 0 --:--:-- --:--:-- --:--:-- 14357
[root@control ~]# chmod 755 control_setup.sh
[root@control ~]# ./control_setup.sh
[root@control ~]# source ~/.bash_profile
スクリプトの実行が完了したら、必要なツール(Ansible,Serverspec等)がイントールされていることを確認しましょう。
[root@control ~]# ansible --version
ansible 2.0.0.1 (v2.0.0.1-1 a50d1ea756) last updated 2017/09/14 11:06:46 (GMT +900)
lib/ansible/modules/core: (detached HEAD b895ac0425) last updated 2017/09/14 11:06:51 (GMT +900)
lib/ansible/modules/extras: (detached HEAD 3b12cc7e54) last updated 2017/09/14 11:06:56 (GMT +900)
config file =
configured module search path = Default w/o overrides
[root@control ~]# gem list | grep serverspec
serverspec (2.37.0)
コントロールマシンに SHIFT ware ダウンロードしましょう。
[root@control ~]# git clone https://github.com/SHIFT-ware/shift_ware.git
コントロールマシンにログインし、以下のディレクトリに移動します。
[root@control ~]# cd shift_ware/Shift_Env/tools/
PreDevツールの設定ファイルを作成します。ここではあらかじめ用意されているサンプルファイルを編集します。
[root@control tools]# cp 1-9901_PreDev.inventory.sample 1-9901_PreDev.inventory
[root@control tools]# vi 1-9901_PreDev.inventory
編集後の設定ファイルは以下の様になります。
[targethost]
192.168.151.11 ansible_ssh_pass=(rootユーザのパスワード)
[targethost:vars]
ansible_ssh_port=22
#全台共通の場合はここに記載
#ansible_ssh_pass=password
PreDevツールを実行します。
[root@control ~]# cd ~/shift_ware
[root@control shift_ware]# Shift_Bin/tools/1-9901_PreDev.sh run
1-9901_PreDev.sh run is doing...
-----------------------------------------------------
2017/09/15 17:01:48 [ 1-9901_PreDev run ] start
PLAY [1-9901_PreDev] ***********************************************************
・・・
PLAY RECAP *********************************************************************
192.168.151.11 : ok=20 changed=11 unreachable=0 failed=0
2017/09/15 17:03:26 [ 1-9901_PreDev run ] end
-----------------------------------------------------
ok, changedの数字のみカウントアップされていれば正常に実行できています。 これで、SHIFT wareを実行するためのターゲットマシン1の設定が完了しました。
ツール実行PCで https://gallery.technet.microsoft.com/Hyper-V-Network-VSP-Bind-cf937850 からダウンロードした「Microsoft_Nvspbind_package.EXE」を実行し、展開されたファイル「nvspbind.exe」を取り出します。また、https://support.microsoft.com/kb/2842230 から「Windows8-RT-KB2842230-x64.msu」をダウンロードします。取得したファイルはコントロールマシンのAnsible/tools/2-9901_PreDev/filesに配置しておきましょう。
[root@control ~]# ls -l shift_ware/Ansible/tools/2-9901_PreDev/files/
total 2388
-rw-r--r--. 1 root root 74752 Sep 15 15:15 nvspbind.exe
-rw-r--r--. 1 root root 2363568 Sep 15 15:15 Windows8-RT-KB2842230-x64.msu
次にConfigureRemotingForAnsible.ps1をダウンロードし、コントロールマシンに配置しておきましょう。
[root@control ~]# cd ~/shift_ware
[root@control shift_ware]# curl -o Ansible/tools/2-9901_PreDev/PSscripts/ConfigureRemotingForAnsible.ps1 https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1
リモートデスクトップを使ってターゲットマシン2にAdministratorユーザでログインし、コントロールマシンにダウンロードしたSHIFT wareから以下のフォルダをコピーします。
/root/shift_ware/Ansible/tools/2-9901_PreDev/PSscripts
ターゲットマシン2で、コピーしたPowerShellのスクリプトを実行します。
PS C:\Users\Administrator\Desktop\PSscripts> .\ConfigureRemotingForAnsible.ps1
wxf : http://schemas.xmlsoap.org/ws/2004/09/transfer
a : http://schemas.xmlsoap.org/ws/2004/08/addressing
w : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
lang : ja-JP
Address : http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
ReferenceParameters : ReferenceParameters
OK
コントロールマシンにログインし、以下のディレクトリに移動します。
[root@control ~]# cd shift_ware/Shift_Env/tools/
PreDevツールの設定ファイルを作成します。ここではあらかじめ用意されているサンプルファイルを編集します。
[root@control tools]# cp 2-9901_PreDev.inventory.sample 2-9901_PreDev.inventory
[root@control tools]# vi 2-9901_PreDev.inventory
編集後の設定ファイルは以下の様になります。
[targethost]
192.168.151.12 ansible_user=Administrator ansible_ssh_pass=(Administratorユーザのパスワード)
[targethost:vars]
ansible_ssh_port = 5986
ansible_connection = winrm
#全台共通の場合はここに記載
#ansible_ssh_pass=password
PreDevツールを実行します。
[root@control shift_ware]# cd ~/shift_ware
[root@control shift_ware]# Shift_Bin/tools/2-9901_PreDev.sh run
2-9901_PreDev.sh run is doing...
-----------------------------------------------------
2017/09/15 13:56:20 [ 2-9901_PreDev run ] start
PLAY [2-9901_PreDev] ***********************************************************
・・・
PLAY RECAP *********************************************************************
192.168.151.12 : ok=5 changed=2 unreachable=0 failed=0
2017/09/15 13:56:31 [ 2-9901_PreDev run ] end
-----------------------------------------------------
ok, changedの数字のみカウントアップされていれば正常に実行できています。 これで、SHIFT wareを実行するためのターゲットマシン2の設定が完了しました。
リリースページから最新バージョンのExcel2YAMLをツール実行PCにダウンロードし、ダブルクリックで開きます。
「Inventory」シートのサーバネーム、リモートユーザ、パスワード列に、ターゲットマシン1、ターゲットマシン2のIPアドレス、ログインユーザ名、ログインパスワードをそれぞれ記入します。また、ターゲットマシン1の行は適用するRole(1-0001_Base)にのみ「◯」、それ以外は「✕」を記入します。
同様にターゲットマシン2の行は適用するRole(2-0001_Base)にのみ「◯」、それ以外は「✕」を記入します。
「インベントリファイルを作成」ボタンを押下すると「inventory」フォルダにインベントリファイルが出力されます。
出力されたファイル(Ansible.1.inventory,Serverspec.1.inventory)をコントロールマシンに転送しましょう。
[root@control Shift_Env]# pwd
/root/shift_ware/Shift_Env
[root@control Shift_Env]# ls -l
total 12
-rw-r--r--. 1 root root 1799 Sep 19 13:57 Ansible.1.inventory
drwxr-xr-x. 3 root root 18 Sep 15 15:15 files
drwxr-xr-x. 2 root root 21 Sep 15 15:15 host_vars
-rw-r--r--. 1 root root 0 Sep 15 15:15 properties.yml
-rw-r--r--. 1 root root 217 Sep 19 13:57 Serverspec.1.inventory
drwxr-xr-x. 2 root root 4096 Sep 15 17:00 tools
再びツール実行PCでExcel2YAMLツールを開き、今回使用しない「Redhat65」「Win2012」シートを削除します。
次に「Redhat71」シートを開き、「No.1 接続用) ホスト名/IPアドレス」にターゲットマシン1のIPアドレスを記入します。 また、今回設定するユーザ設定、グループ設定(No.10〜29)以外の値は空欄にします。
次に「Win2012R2」シートを開き、「No.1 接続用) ホスト名/IPアドレス」にターゲットマシン2のIPアドレスを記入します。 また、今回設定するユーザ設定、グループ設定(No.13〜28)以外の値は空欄にします。
「サーバ設定ファイルを作成」ボタンを押下すると「property」フォルダにパラメータ指定ファイルが出力されます。
出力されたファイル(host_vars/192.168.151.**.yml,properties.yml)をコントロールマシンに転送しましょう。
[root@control Shift_Env]# pwd
/root/shift_ware/Shift_Env
[root@control Shift_Env]# ls -l
total 16
-rw-r--r--. 1 root root 1799 Sep 19 13:57 Ansible.1.inventory
drwxr-xr-x. 3 root root 18 Sep 15 15:15 files
drwxr-xr-x. 2 root root 71 Sep 19 15:08 host_vars
-rw-r--r--. 1 root root 1271 Sep 19 2017 properties.yml
-rw-r--r--. 1 root root 217 Sep 19 13:57 Serverspec.1.inventory
drwxr-xr-x. 2 root root 4096 Sep 15 17:00 tools
[root@control Shift_Env]# ls -l host_vars/
total 8
-rw-r--r--. 1 root root 573 Sep 19 2017 192.168.151.11.yml
-rw-r--r--. 1 root root 695 Sep 19 2017 192.168.151.12.yml
では、コントロールマシンからAnsibleのロールを実行してみましょう。
[root@control shift_ware]# pwd
/root/shift_ware
[root@control shift_ware]# Shift_Bin/Ansible-play.sh run
Ansible-play.sh run is doing...
-----------------------------------------------------
2017/09/19 15:49:08 [ Ansible run ] start
・・・
PLAY RECAP *********************************************************************
192.168.151.11 : ok=9 changed=3 unreachable=0 failed=0
192.168.151.12 : ok=19 changed=1 unreachable=0 failed=0
2017/09/19 15:49:38 [ Ansible run ] end
-----------------------------------------------------
ok, changedの数字のみカウントアップされていれば正常に実行できています。 ターゲットマシン1にユーザtest1,test2が、ターゲットマシン2にユーザtestuserがそれぞれ追加されていることを確認してみましょう。
[root@target1 ~]# cat /etc/passwd | grep test
test1:x:1000:1002::/home/test1:/bin/bash
test2:x:1001:1003::/home/test2:/bin/bash
ターゲットマシンが正常に設定されていることをServerspecでテストしてみましょう。
[root@control shift_ware]# pwd
/root/shift_ware
[root@control shift_ware]# Shift_Bin/Spec-play.sh run
Spec-play.sh run is doing...
-----------------------------------------------------
2017/09/20 11:07:27 [ Serverspec run ] start
・・・
192.168.151.11: OK=16 NG=0
192.168.151.12: OK=12 NG=0
Finished in 6.16 seconds (files took 0.923 seconds to load)
12 examples, 0 failures
2017/09/20 11:07:35 [ Serverspec run ] end
-----------------------------------------------------
OKの数字のみカウントアップされていればテストは成功です。 おつかれさまでした。