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:
1 |
ansible-playbook -i myhost.local, playbook.yml |
Another, but with an IP:
1 |
ansible-playbook -i 10.200.23.10, playbook.yml |
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:
1 2 3 4 5 |
- hosts: all vars: myvar: something roles: - role: ericsysmin.ntp |
Hopefully this helps in your automation endeavors.