How to run Ansible without specifying the inventory but the host directly?

Ngoc Tran picture Ngoc Tran · Jun 19, 2013 · Viewed 86.5k times · Source

I want to run Ansible in Python without specifying the inventory file through (ANSIBLE_HOST) but just by:

ansible.run.Runner(
  module_name='ping',
  host='www.google.com'
)

I can actually do this in fabric easily but just wonder how to do this in Python. On the other hand, documentation of the Ansible API for python is not really complete.

Answer

trkoch picture trkoch · Aug 15, 2013

Surprisingly, the trick is to append a ,

# Host and IP address
ansible all -i example.com,
ansible all -i 93.184.216.119,

or

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

The host parameter preceding the , can be either a hostname or an IPv4/v6 address.