#contents ** Ansibleとはなにか? [#lf812133] - 概要:サーバーの構成管理ツール - 公式サイト: -- 公式サイト: www.ansible.com -- ドキュメンテーション: docs.ansible.com - 知識: -- Unixコマンド -- Vim -- Vagrant -- YAML - 環境: -- MacOS X -- Vagrant ** サーバー構成 [#xfe74c1f] - Host -- Ansible -- Python実行環境 -- Inventory:どのサーバーを管理するか記述 -- ansible.cfg:Ansible全体の設定を記述 -- Playbook:管理対象に対して具体的にどのような設定(構成)を行うか記述 - Web -- 管理対象 -- Python実行環境 -- Hostとの鍵認証/SSH接続 -- User / Apache / PHP ※Ansibleで構成管理 - DB -- 管理対象 -- Python実行環境 -- Hostとの鍵認証/SSH接続 -- User / MySQL ※Ansibleで構成管理 ** Vagrantでサーバーを起動 [#lc2bfb4d] - 利用可能なBoxファイルを検索 -- [[Atlas:https://atlas.hashicorp.com/boxes/search?utm_source=vagrantcloud.com&vagrantcloud=1]] >> Discover Vagrant Boxes - CentOS6.5のVagrantfileを生成 $ cd ~/Documents/MyVagrant $ mkdir ansible_lessons $ cd ansible_lessons $ vagrant init bento/centos-6.7 - Vagrantfileを開き下記をコメントアウト $ vi Vagrantfile config.vm.box = "bento/centos-6.7" - 下記を貼り付け config.vm.define "host" do |node| node.vm.box = "bento/centos-6.7" node.vm.hostname = "host" node.vm.network :private_network, ip: "192.168.43.51" end config.vm.define "web" do |node| node.vm.box = "bento/centos-6.7" node.vm.hostname = "web" node.vm.network :private_network, ip: "192.168.43.52" end config.vm.define "db" do |node| node.vm.box = "bento/centos-6.7" node.vm.hostname = "db" node.vm.network :private_network, ip: "192.168.43.53" end $ vagrant up ... ... ==> host: Successfully added box 'bento/centos-6.7' (v2.2.7) for 'virtualbox'! ... ... $ vagrant status Current machine states: host running (virtualbox) web running (virtualbox) db 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`. ** Ansibleをインストールしてみよう [#ja6cc9b9] - Ansibleをインストールするhostにssh接続 $ vagrant ssh host - epelリポジトリをダウンロード -- [[Index of /pub/epel/6/x86_64:https://dl.fedoraproject.org/pub/epel/6/x86_64/]]より[[epel-release-6-8.noarch.rpmのリンクアドレス:https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm]]をコピー [vagrant@host ~]$ wget https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm - epelリポジトリをインストール [vagrant@host ~]$ sudo rpm -Uvh epel-release-6-8.noarch.rpm - Ansibleをインストール [vagrant@host ~]$ sudo yum -y install ansible [vagrant@host ~]$ $ ansible --version ansible 2.1.1.0 config file = /etc/ansible/ansible.cfg configured module search path = Default w/o overrides