Running Ansible without an Inventory File

January 29, 2017

So, it seems this isn’t widely used or documented, but it is possible to run a playbook without passing through an inventory file.

To do so we need to use the following example:

Another, but with an IP:

It’s very handy when trying to deploy hosts but you don’t want to need to manage static files with host entries. However, there are a few things to keep in mind. You will need to pass the user via command line, or in the playbook itself. Using the command line,  -u REMOTE_USER, or --user=REMOTE_USER .

The , (comma) after the host is EXTREMELY important. Without this, it will look for a file to load in your current working directory. Which isn’t the case when we are trying to execute a host simply from IP.

You will also need to set hosts to all, in your playbook. Failure to do so will also cause a failure.

Example:

Hopefully this helps in your automation endeavors.

Leave a Reply