On Wednesday, 14 November 2018 17:19:38 CET Bob Harold wrote:
> On Tue, Nov 13, 2018 at 5:37 PM Brian Coca <bc...@redhat.com> wrote:
> 
> > 1 play before your normal play:
> >
> >
> > hosts: hosta,hostb
> > gather_facts: False
> > tasks:
> >    - ping:
> >    - group_by: key=rechable
> >
> > hosts: reachable
> > ....
> >
> > ----------
> > Brian Coca
> >
> 
> Thanks for mentioning the 'ping' module - that is new to me.  (It checks
> ssh connection and python, not an icmp ping)
> But I don't see "reachable" as a return value in the docs.

It's not a return value.
group_by is a module that will add the host in a group call rechable.


> Looks like that will run it for both hosts, which is not what the requestor
> wanted.  More like:
> 
> hosts: hosta
> gather_facts: False
> tasks:
>    - ping:
>      register: pingtest
>    - hosts: hostb
>      when: pingtest.failed
> 
> But so far I cannot get it to work.
> 
> I am looking to use the same logic to connect to the internal or external
> IP of an AWS server depending on where I happen to be running Ansible at
> that moment.

This will run on the first host in the list(host2) if it reachable if not it 
will run on the second host(host1)
Not pretty but should work.

---
- hosts:
    - host2
    - host1
  gather_facts: no
  serial: 1
  ignore_unreachable: true
  tasks:
    - ping:
      register: r
    - group_by:
        key: rechable_hosts
      when: r.unreachable is not defined

- hosts: rechable_hosts[0]
  tasks:
    - ping:


-- 
Kai Stian Olstad


-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to