6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ansible — playbook から他のplaybook を実行する ( import_playbook )

Last updated at Posted at 2018-06-30

echo するだけのplaybookを用意

import される側

echo.yml
---
- hosts: example
  tasks:
    - name: just echo message
      debug:
        msg: THIS IS THE MESSAGE

そのplaybookを三回実行するplaybook

import_playbook をベタな階層に書いていく。
playbook はそもそも hosts に対しての動作の塊なので、 他のplaybookを呼ぶ時にホスト指定というものはない。

import_playbooks.yml
---
- name: first import other playbook
  import_playbook: echo.yml

- name: second import other playbook
  import_playbook: echo.yml

- name: third import other playbook 
  import_playbook: echo.yml

実行例

記述通りに echo.yml が3回実行されるのが分かる。

ansible-playbook -i inventory.txt import_playbooks.yml


PLAY [example] ***********************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************
ok: [localhost]

TASK [just echo message] *************************************************************************************************************************
ok: [localhost] => {
    "msg": "THIS IS THE MESSAGE"
}

PLAY [example] ***********************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************
ok: [localhost]

TASK [just echo message] *************************************************************************************************************************
ok: [localhost] => {
    "msg": "THIS IS THE MESSAGE"
}

PLAY [example] ***********************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************
ok: [localhost]

TASK [just echo message] *************************************************************************************************************************
ok: [localhost] => {
    "msg": "THIS IS THE MESSAGE"
}

PLAY RECAP ***************************************************************************************************************************************
localhost                  : ok=8    changed=0    unreachable=0    failed=0

環境

  • ansible2.4

参考

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?