I have an Ansible variable containing a list of web servers (all on the same host):
servers:
- foo
- bar
- baz
And a task that modifies their configuration files and registers the results in a variable:
- name: create server configs
template: ...
with_items: "{{ servers }}"
notify: restart changed servers
register: servers_changed
And a handler that restarts only the servers that change during this task:
- name: restart changed servers
command: restart-my-server {{ item.item.name }}
when: item.changed
with_items: "{{ servers_changed.results }}"
My problem is that now I need several tasks, like the ones above, that change different configuration files. But if I do, they will overwrite the variable servers_changed, so only the latter will be used.
I can register different variables in each task, but then I need a different handler for each of them. It will be random. Is there a better way?