On Wednesday, November 14, 2018 at 11:19:55 AM UTC-5, Bob Harold wrote:
>
>
> On Tue, Nov 13, 2018 at 5:37 PM Brian Coca <bc...@redhat.com <javascript:>> 
> wrote:
>
>> 1 play before your normal play:
>>
>>
>> hosts: hosta,hostb
>> gather_facts: False
>> tasks:
>>    - ping:
>>    - group_by: key=rechable
>>
>> hosts: reachable
>> ....
>>
>
> 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.
>
> 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.
>

You might be interested in a proof of concept inventory plugin I wrote a 
few months back: https://github.com/flowerysong/ansible/commit/900b3001

A better implementation would be to do this at the connection layer so that 
the checking is done on demand instead of serially for every host in the 
inventory, but the inventory plugin approach works and isn't unbearably 
slow for small inventories.

We don't actually use this in production; for AWS our team uses Amazon's 
DNS resolution, so the hostnames resolve to the internal IPs from within 
the VPC or the external IPs from outside:

ezekielh@ego ~ $ dig +short just-gofannon.ctools-mx.a.mail.umich.edu
ec2-52-15-122-141.us-east-2.compute.amazonaws.com.
10.0.74.217

zeke@ironbull ~ $ dig +short just-gofannon.ctools-mx.a.mail.umich.edu
ec2-52-15-122-141.us-east-2.compute.amazonaws.com.
52.15.122.141

-- 
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