If you set a fact on a specific host you'll be able to look that up
via hostvars from anywhere:

   http://docs.ansible.com/ansible/set_fact_module.html

On 29 September 2016 at 07:50, Rafał Radecki <[email protected]> wrote:
> Hi All :)
>
> I am currently trying to find a way to set a variable/fact on all hosts in
> case a directory for a service will already exist on one of the play's
> hosts. Basically:
>
> # check if dir exists on all hosts and set service_home_dir_status on every
> host
> - name: check if service home dir already exists
>   stat:
>     path: "{{ service_home_dir }}"
>   register: service_home_dir_status
>
> # fail if the above dir already exists
> - name: fail if service home dir already exists
>   fail:
>     msg: "Home directory for service {{ service_home_dir }} already exists.
> Please check the situation!"
>   when: service_home_dir_status.stat.isdir is defined and
> service_home_dir_status.stat.isdir
>
> The problem with above code is that if for example I have a group of hosts:
> host1, host2, host3 and on host1 the directory already exists the second
> step will only fail on host1 and succeed on host2 and host3.
> Is there a way to maybe set a fact for all hosts in between these tasks if
> the directory already exists on one of them?
>
> Thanks!
>
> BR,
> Rafal.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/7f384473-2f59-409d-abf2-e3ccb0bf30c9%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAK5eLPT68TPsU1ucB0iherfXAN0RmLcx5oiUoH1WtCbUd4o%2Bqg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to