Connecting to hosts without consistent IPs or DNS

This is a pretty generic query that’s come up for me a lot over years. I’ve never really needed to resolve it but now I do.

I currently run an AWX installation that does basic management of various resources like patching etc. In some cases, I add hosts with names like server1.mydomain.com (where we have a DNS entry for the server), or more commonly something like 100.50.20.21 etc etc. This works well.

I would like to start managing some standard PCs that don’t have any such identifiers. Specifically, we have remote PCs that connect to our VPN (and AWX is peered to the VPN network) and when they do are assigned an address from 10.8.0.x.

I’m looking for a good way to do one of two (or ideally both) things.

  1. Find all the currently connected devices on that range and run some scripts on them
  2. Add hosts to my inventory where I don’t have a specific IP or FQDN for the device, i.e. some other identifier so that AWX knows where to go, then run some scripts on it.

For the second point, it could be that I ask everyone to be connected. Or ideally I could just run scripts on those that are connected at that time and report those that aren’t so that I could then run it later on specific hosts that were excluded the time before.

Bit complicated I know but my fundamental lack of knowledge of the inner workings of ansible is holding me back a bit here. It might be wishful thinking.

Use the facts and go based off MAC as that won’t change… generally… I set mine to spoof macs on open networks prior to VPN… theoretically though either define the run as MAC or host name lookup derived and you should be fine.

If all your PC machines start with FRED then you could fuzzy search on all connected hosts on that with host name like FRED and be pretty accurate in your plan execution. Little logic in the playbook will help offset any other issues/snowflakes and you can run it as a workflow to scan and dump names and then run another playbook (role inclusion) on those new hosts.

Thanks for that, but I’m not sure what you mean by " Use the facts". You mean run some kind of search of all hosts on the network and then run based on a pre-defined set up MACs or something like that?

I’ve been looking at using a smart inventory but not sure if this will work for my use case. And can’t figure out from the documentation how to define the smart host filter either.