Ansible Documentation
import_tasks – Import a task list機能
- 現在の playbook に別ファルに書かれたタスクを取り込む
- このモジュールに loop ディレクティブは指定できない
パラメータ
| パラメータ | 選択肢/ Default | 説明 |
|---|---|---|
| free-form | - | 取り込むタスクのファイル名を指定する |
例
■ メインスクリプト---
- hosts: all
tasks:
- name: 前メッセージ
debug:
msg: "インポート前"
- name: タスクのインポート
import_tasks: sample.yml
when: ansible_facts['distribution'] == "CentOS"
- name: 後メッセージ
debug:
msg: "インポート後"
■ sample.yml
- name: ディストリビューション名を表示
debug:
var: ansible_facts['distribution']
■ 実行結果
ansibleman@ubuntu-pc:~/ansible/import-tasks$ ansible-playbook -i hosts.yml site.yml
PLAY [all] ***********************************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************************
ok: [node-c0706]
TASK [前メッセージ] ********************************************************************************************************************
ok: [node-c0706] => {
"msg": "インポート前"
}
TASK [ディストリビューション名を表示] ***********************************************************************************************************
ok: [node-c0706] => {
"ansible_facts['distribution']": "CentOS"
}
TASK [後メッセージ] ********************************************************************************************************************
ok: [node-c0706] => {
"msg": "インポート後"
}
PLAY RECAP ***********************************************************************************************************************
node-c0706 : ok=4
changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ansibleman@ubuntu-pc:~/ansible/import-tasks$