Ansibleの環境を準備する

## まずは、サーバの準備！

Vagrant、VirtualBoxをインストール。
CentOS 6.7のBoxをチョイス。

vagrantfileを編集。

```vagrantfile
Vagrant.configure(2) do |config|
  config.vm.define "controller" do |node|
        node.vm.box = "bento/centos-6.7"
        node.vm.hostname = "controller"
        node.vm.network :private_network, ip: "192.168.100.10"
        node.vm.network :forwarded_port, id: "ssh", guest: 22, host: 2210
  end
  config.vm.define "target" do |node|
        node.vm.box = "bento/centos-6.7"
        node.vm.hostname = "target"
        node.vm.network :private_network, ip: "192.168.100.20"
        node.vm.network :forwarded_port, id: "ssh", guest: 22, host: 2220
  end
end
```

そして、起動してみる。

```Terminal
$ vagrant up

Bringing machine 'controller' up with 'virtualbox' provider...
Bringing machine 'target' up with 'virtualbox' provider...
==> controller: Importing base box 'bento/centos-6.7'...
==> controller: Matching MAC address for NAT networking...
==> controller: Checking if box 'bento/centos-6.7' is up to date...
==> controller: Setting the name of the VM: centos6_controller_1483801762189_29234
==> controller: Clearing any previously set network interfaces...
==> controller: Preparing network interfaces based on configuration...
    controller: Adapter 1: nat
    controller: Adapter 2: hostonly
==> controller: Forwarding ports...
    controller: 22 (guest) => 2210 (host) (adapter 1)
==> controller: Booting VM...
==> controller: Waiting for machine to boot. This may take a few minutes...
    controller: SSH address: 127.0.0.1:2210
    controller: SSH username: vagrant
    controller: SSH auth method: private key
    controller: Warning: Remote connection disconnect. Retrying...
    controller: Warning: Remote connection disconnect. Retrying...
    controller: 
    controller: Vagrant insecure key detected. Vagrant will automatically replace
    controller: this with a newly generated keypair for better security.
    controller: 
    controller: Inserting generated public key within guest...
    controller: Removing insecure key from the guest if it's present...
    controller: Key inserted! Disconnecting and reconnecting using new SSH key...
==> controller: Machine booted and ready!
==> controller: Checking for guest additions in VM...
    controller: The guest additions on this VM do not match the installed version of
    controller: VirtualBox! In most cases this is fine, but in rare cases it can
    controller: prevent things such as shared folders from working properly. If you see
    controller: shared folder errors, please make sure the guest additions within the
    controller: virtual machine match the version of VirtualBox you have installed on
    controller: your host and reload your VM.
    controller: 
    controller: Guest Additions Version: 5.0.20
    controller: VirtualBox Version: 5.1
==> controller: Setting hostname...
==> controller: Configuring and enabling network interfaces...
==> controller: Mounting shared folders...
    controller: /vagrant => /Users/gooska/vagrant/centos6
==> target: Importing base box 'bento/centos-6.7'...
==> target: Matching MAC address for NAT networking...
==> target: Checking if box 'bento/centos-6.7' is up to date...
==> target: Setting the name of the VM: centos6_target_1483801959201_25291
==> target: Clearing any previously set network interfaces...
==> target: Preparing network interfaces based on configuration...
    target: Adapter 1: nat
    target: Adapter 2: hostonly
==> target: Forwarding ports...
    target: 22 (guest) => 2220 (host) (adapter 1)
==> target: Booting VM...
==> target: Waiting for machine to boot. This may take a few minutes...
    target: SSH address: 127.0.0.1:2220
    target: SSH username: vagrant
    target: SSH auth method: private key
    target: Warning: Remote connection disconnect. Retrying...
    target: 
    target: Vagrant insecure key detected. Vagrant will automatically replace
    target: this with a newly generated keypair for better security.
    target: 
    target: Inserting generated public key within guest...
    target: Removing insecure key from the guest if it's present...
    target: Key inserted! Disconnecting and reconnecting using new SSH key...
==> target: Machine booted and ready!
==> target: Checking for guest additions in VM...
    target: The guest additions on this VM do not match the installed version of
    target: VirtualBox! In most cases this is fine, but in rare cases it can
    target: prevent things such as shared folders from working properly. If you see
    target: shared folder errors, please make sure the guest additions within the
    target: virtual machine match the version of VirtualBox you have installed on
    target: your host and reload your VM.
    target: 
    target: Guest Additions Version: 5.0.20
    target: VirtualBox Version: 5.1
==> target: Setting hostname...
==> target: Configuring and enabling network interfaces...
==> target: Mounting shared folders...
    target: /vagrant => /Users/gooska/vagrant/centos6
```

ステータスを確認する。

```Terminal
$ vagrant status 
Current machine states:

controller                running (virtualbox)
target                    running (virtualbox)

This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.
```

各サーバへの接続。

```Terminal
$ vagrant ssh controller
$ vagrant ssh target
```

## つづいて、Ansibleの準備！

Pythonのバージョンを確認。2.6.x以上ってことで。

```Terminal
[vagrant@controller ~]$ python --version
Python 2.6.6
```

つづいて、yumでAnsibleをインストール。
Ansible は CentOS や RHEL の標準 yum リポジトリでは提供されていませんが、EPEL のリポジトリで提供されています。

RedHat 6系 (64bit)
http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

```Terminal
yum localinstall http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
```

では、Ansibleのインストール。

```Terminal
$ sudo yum install ansible

インストール:
  ansible.noarch 0:2.2.0.0-3.el6                                                                                        

依存性関連をインストールしました:
  PyYAML.x86_64 0:3.10-3.1.el6                                libyaml.x86_64 0:0.1.3-4.el6_6                            
  python-babel.noarch 0:0.9.4-5.1.el6                         python-crypto.x86_64 0:2.0.1-22.el6                       
  python-crypto2.6.x86_64 0:2.6.1-2.el6                       python-httplib2.noarch 0:0.7.7-1.el6                      
  python-jinja2-26.noarch 0:2.6-3.el6                         python-keyczar.noarch 0:0.71c-1.el6                       
  python-markupsafe.x86_64 0:0.9.2-4.el6                      python-paramiko.noarch 0:1.7.5-2.1.el6                    
  python-pyasn1.noarch 0:0.0.12a-1.el6                        python-setuptools.noarch 0:0.6.10-3.el6                   
  python-simplejson.x86_64 0:2.0.9-3.1.el6                    python-six.noarch 0:1.9.0-2.el6                           
  sshpass.x86_64 0:1.05-1.el6                                

完了しました!
```

ansibleのバージョンを確認。

```Terminal
$ ansible --version
ansible 2.2.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
```