Tuesday, 11 December 2018 16:52

Call an Ansible Playbook Without an Inventory File

Written by
Rate this item
(0 votes)

Call Ansible with an IP address or hostname as the inventory (-i) argument.

The trick is to append a "," (comma) to the hostname or IPv4/v6 address on the command line:

$ ansible all -i host.example.com, [the rest of the directive here…]
$ ansible all -
i 10.17.234.197,  [the rest of the directive here…]

To run a playbook for just one host, make sure the hosts directive in the playbook contains all and call ansible-playbook like the above:

# Requires 'hosts: all' in your playbook
$ ansible-playbook -i host.example.com, playbook.yml

In both cases, the host parameter preceding the comma can be either a hostname or an IPv4/v6 address.

This works because if Ansible notices a comma, it thinks it is a list of hosts, but you are actually only defining one.

Last modified on Tuesday, 11 December 2018 18:44
Steve Cote

Steve has been a systems architect for the telecommunications and electric utility industries creating circuit provisioning systems and smart grid solutions. He is a hands-on architect working with teams to deliver large complex projects. More recently, Steve has been consulting agile teams from Fortune 15 organizations, start-ups, and everything in-between to be more productive with DevOps and agile practices.

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.