Skip to content

Instantly share code, notes, and snippets.

@heiwa4126
Created March 10, 2021 02:43
Show Gist options
  • Save heiwa4126/f11035e0cc208fabd7cb9f7013557f36 to your computer and use it in GitHub Desktop.
Save heiwa4126/f11035e0cc208fabd7cb9f7013557f36 to your computer and use it in GitHub Desktop.
最初に1回、最後に1回なにかするAnsibleのplaybook. 各ホストからXMLファイルあつめて最後に集計する、みたいなときに使う。
- name: do anything at first and at last
hosts: hosts1
become: false
gather_facts: false
tasks:
- name: at 1st
debug:
msg: "run only on {{ inventory_hostname }} at first"
changed_when: true # notifyはchangedでないと発生しないので
notify: last_one
run_once: true
- name: do something
debug: var=inventory_hostname
- name: do something again
debug: var=inventory_hostname
handlers:
- name: at last
listen: last_one
debug:
msg: "run only on {{ inventory_hostname }} at last"
@heiwa4126
Copy link
Author

heiwa4126 commented Mar 10, 2021

インベントリは

[hosts1]
l1 ansible_host=localhost ansible_python_interpreter=/usr/bin/python3
l2 ansible_host=localhost ansible_python_interpreter=/usr/bin/python3
l3 ansible_host=localhost ansible_python_interpreter=/usr/bin/python3

こんな感じのを書いとくとテストが楽。`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment