Skip to content

Instantly share code, notes, and snippets.

@goozbach
Last active August 10, 2016 21:07
Show Gist options
  • Save goozbach/a0c4442f1ea729171c1568a51ac51612 to your computer and use it in GitHub Desktop.
Save goozbach/a0c4442f1ea729171c1568a51ac51612 to your computer and use it in GitHub Desktop.
Ansible handler questions.

Had some questions at work about what handlers could do. So we built this playbook to test.

  • handlers can be called "dynamicly" ie called with variable name.
  • handlers can iterate over a list.
---
- name: hahah
hosts: all
connection: local
become: true
become_method: sudo
vars:
foo:
- foo
- bar
- baz
handlers:
- name: run foo
debug: msg="running foo"
- name: run bar
debug: msg="running bar"
- name: run baz
debug: msg="running baz with {{ item }}"
with_items: "{{ foo }}"
tasks:
- command: touch /tmp/{{ item }} warn=false
notify:
- run {{ item }}
with_items: "{{ foo }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment