#author("2019-01-19T09:02:29+00:00","default:haikikyou","haikikyou")
[[Ansible]]
Ansibleのinventoryのパターンを以下にまとめる。~
良い例があれば随時追加。
* Primary and Standby [#e9a2feeb]
- PostgreSQLのようなDBサーバで、PrimaryとStandbyサーバをセットアップする。
- primaryとstandbyのグループで構成
- primaryは複数指定される可能性があるが、プレイブックで1つのノードを選択。
- standbyでは、同期と非同期のパターンがありhostvarsで処理分けする。
''hosts''
#geshi{{{
[primary]
127.0.0.1
[standby]
127.0.0.1 replica_mode=sync
192.168.3.4 replica_mode=async
}}}
''playbook.yml''
#geshi(YAML){{{
- hosts: primary[0]
tasks:
- debug: msg="setup a primary server"
- hosts: standby
tasks:
- block:
- debug: msg="Here is in synchronous server block"
when: hostvars[inventory_hostname]['replica_mode'] == 'sync'
- block:
- debug: msg="Here is in asynchronous server block"
when: hostvars[inventory_hostname]['replica_mode'] == 'async'
}}}
実行結果は以下のようになる。
#geshi(bash){{{
$ ansible-playbook -i hosts playbook.yml -v
PLAY [primary[0]] ****************************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************************
ok: [127.0.0.1]
TASK [debug] *********************************************************************************************************************
ok: [127.0.0.1] => {
"msg": "setup a primary server"
}
PLAY [standby] *******************************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************************
ok: [127.0.0.1]
ok: [192.168.3.4]
TASK [debug] *********************************************************************************************************************
skipping: [192.168.3.4] => {}
ok: [127.0.0.1] => {
"msg": "Here is in synchronous server block"
}
TASK [debug] *********************************************************************************************************************
skipping: [127.0.0.1] => {}
ok: [192.168.3.4] => {
"msg": "Here is in asynchronous server block"
}
PLAY RECAP ***********************************************************************************************************************
127.0.0.1 : ok=4 changed=0 unreachable=0 failed=0
192.168.3.4 : ok=2 changed=0 unreachable=0 failed=0
}}}