Choosing and adhoc host without inventory file

Sometimes I just want to contact a random host (this host’s IP is ephemeral/discovered during the operation), and execute an adhoc module.

Is there a way to do this?

It seems Ansible always requires an inventory file, but editing the inventory file just to do an adhoc command on a host address that won’t exist afterwards is a bit unnecessary.

For simple testing, you can use the “-i ,” syntax (don’t forget the comma at the end, it is required). This should only be used for testing purposes, we always recommend you use some sort of inventory file or dynamic inventory script for regular use.

I use a “local” inventory file with a single line for this:

127.0.0.1

Regards,
-scott