Ansible

Ansibleのinventoryのパターンを以下にまとめる。
良い例があれば随時追加。

Primary and Standby

hosts

[primary]
127.0.0.1

[standby]
127.0.0.1    replica_mode=sync
192.168.3.4  replica_mode=async

playbook.yml

- 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'

実行結果は以下のようになる。

$ 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
 

トップ   差分 バックアップ リロード   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
目次
ダブルクリックで閉じるTOP | 閉じる
GO TO TOP