ansible. Run handler on specific host

463 Views Asked by At

I need to collect some information during run of ansible and print this information in the end.

I've tried to define empty list variable in role. I added in playbook handler which add new value to list ant print value of this variable in the end of playbook.

  set_fact:
    manual_tasks: "{{ manual_tasks + ['restart apache'] }}"

I miss that set_fact host related. So this solution stop working as soon as I start using different hosts. Delegate_to is not solve problem as well. Is there way to make this list global? Or any other solution exist?

1

There are 1 best solutions below

0
On

Q: Add new value to list and print it at the end of the playbook. Is there way to make this list global?

A: No. It is not. "Global scope is set by config, environment variables and the command line." A host can't set_fact in the play or global scope.

You might want to take a look at ansible-runner. See Sending Runner Status and Events to External Systems.