Last active
October 25, 2017 08:17
-
-
Save leedohyung-dba/5f83837529d97bcd56b55b9e040954a9 to your computer and use it in GitHub Desktop.
Ansible自体を知らない人が本番に使える人になるまでのスタディー ref: http://qiita.com/leedohyung-dba/items/59be7006182a8a0b4cc0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ./lee/config/app.php | |
'Datasources' => [ | |
'default' => [ | |
'className' => 'Cake\Database\Connection', | |
'driver' => 'Cake\Database\Driver\Postgres', | |
'persistent' => false, | |
'host' => '192.168.43.55', | |
'port' => '5432', | |
'username' => 'postgres', | |
'password' => '1q2w3e', | |
'database' => 'ansible_std', | |
'encoding' => 'utf8', | |
'timezone' => 'UTC', | |
'flags' => [], | |
'cacheMetadata' => true, | |
'log' => false, | |
'quoteIdentifiers' => false, | |
'url' => env('192.168.43.55', null), | |
], | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ansible all -i "web_a," -a "/bin/echo hello" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
├── host 👉 【インベントリファイル】 | |
├── db.yml 👉 【DBサーバのPlaybook】 | |
├── web.yml 👉 【WEBサーバのPlaybook】 | |
├── roles 👉 【それぞれの状態定義(タスク)があるroleたち】 | |
│ ├── apache | |
│ │ ├── tasks | |
│ │ │ └── main.yml | |
│ │ └── ... | |
│ ├── aws-cli | |
│ │ ├── tasks | |
│ │ │ └── main.yml | |
│ │ └── ... | |
│ ├── common | |
│ │ ├── tasks | |
│ │ │ └── main.yml | |
│ │ └── ... | |
│ ├── php | |
│ │ ├── tasks | |
│ │ │ └── main.yml | |
│ │ └── ... | |
│ └── postgresql | |
│ ├── tasks | |
│ │ └── main.yml | |
│ └── ... | |
└── vars.yml 👉 【交通で使う変数定義】 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ansible-playbook -i host web.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ansible-playbook -i host db.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ansible all -i "web_a," -m template -a "src=./index.php dest=/var/www/html/index.php owner=lee group=lee" --extra-vars '{"host_name":"WEB_A"}' --sudo | |
ansible all -i "web_b," -m template -a "src=./index.php dest=/var/www/html/index.php owner=lee group=lee" --extra-vars '{"host_name":"WEB_B"}' --sudo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ansible-playbook -i host db.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# composer.phar設置 | |
curl -s http://getcomposer.org/installer | php | |
# CakePHPアプリケーション設置 | |
php composer.phar create-project --prefer-dist cakephp/app lee |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bin/cake bake all users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ssh アクセス | |
vagrant ssh host | |
# EPELインストール | |
wget https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm | |
# 有効にする | |
sudo rpm -Uvh epel-release-6-8.noarch.rpm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ansibleインストール | |
sudo yum -y install ansible | |
# バージョン確認 | |
ansible --version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ansible all -i host -m ping |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ansible web_group -i host -m yum -a 'name=tree state=present' --sudo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ansible all -i host -a "/bin/echo hello" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ansible "127.0.0.1," -c local -m yum -a 'name=tree state=present' --sudo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[web_group] | |
web_a | |
web_b | |
[db_group] | |
db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#./ansible/roles/postgresql/tasks/main.yml | |
... | |
# データベースを作成 | |
- name: create database | |
become: true | |
become_user: postgres | |
postgresql_db: name={{ db_name }} login_password={{db_user_password}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#./ansible/roles/postgresql/templates/pg_hba.conf2.j2 | |
... | |
host all all 0.0.0.0/0 trust |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#./playbook.yml | |
--- | |
- name: web | |
become: true | |
hosts: all | |
user: fusic | |
vars_files: | |
- vars.yml | |
roles: | |
- common | |
- apache | |
- php | |
- postgresql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#./ansible/roles/postgresql/files/postgresql.conf | |
... | |
listen_addresses = '*' | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
Vagrant.configure(2) do |config| | |
config.vm.define "host" do |node| | |
node.vm.box = "geerlingguy/centos7" | |
node.vm.hostname = "host" | |
node.vm.network :private_network, ip: "192.168.43.51" | |
end | |
config.vm.define "web.a" do |node| | |
node.vm.box = "geerlingguy/centos7" | |
node.vm.hostname = "web.a" | |
node.vm.network :private_network, ip: "192.168.43.52" | |
end | |
config.vm.define "web.b" do |node| | |
node.vm.box = "geerlingguy/centos7" | |
node.vm.hostname = "web.b" | |
node.vm.network :private_network, ip: "192.168.43.53" | |
end | |
config.vm.define "db" do |node| | |
node.vm.box = "geerlingguy/centos7" | |
node.vm.hostname = "db" | |
node.vm.network :private_network, ip: "192.168.43.55" | |
end | |
config.vm.provider "virtualbox" do |vb| | |
vb.customize ["modifyvm", :id, "--cableconnected1", "on"] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#./ansible/vars.yml | |
... | |
db_name: ansible_std | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: web | |
# Ansible1.9からはsudo/suの代わりにbecomeを使う | |
become: true | |
# webグループだけにタスクする | |
hosts: web_group | |
user: vagrant | |
vars_files: | |
- vars.yml | |
roles: | |
- common | |
- apache | |
- php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
※ ansibleコマンドにはテストするための-Cオプションがあります。 | |
実際は反映しなく、状態定義の実装に失敗があるか確認するための目的です。 | |
ansibleは残念ながら失敗した時、失敗する前のやつがRollBackされないです。 | |
なので、冪等性がないモジュールが含めているTaskでしたら、 | |
一回テストすることをオススメします。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment