Run a playbook with arbitrary host not in the inventory hosts list?

5,750 views
Skip to first unread message

Peter Loron

unread,
Aug 18, 2015, 8:03:06 PM8/18/15
to Ansible Project
Hello. I often want to run a playbook against an arbitrary host, sometimes one not defined in my inventory hosts file. Is there a way of specifying an arbitrary hostname or IP on the ansible-playbook command line to run things this way? It's a pain to have to edit the inventory each time I want to run something against a temporary machine (e.g. for testing).

Thanks.

-Pete

Brian Coca

unread,
Aug 19, 2015, 12:26:04 AM8/19/15
to Ansible Project
-i 'myhost,' will define an inventory on the command line where you
can add any host/ip you want.

^ observe the , is needed even if only 1 host is defined to signify
this is a list and not a path to a file


--
Brian Coca

Peter Loron

unread,
Aug 19, 2015, 2:28:20 PM8/19/15
to Ansible Project
Hi, Brian. I'm trying to run a playbook file which by definition must contain a "hosts" entry. When I run the ansible-playbook command with the "-i" flag, I get this:

> ansible-playbook -i '10.10.10.155,' -u root  do_base_packages.yaml


PLAY
[dummy] ******************************************************************
skipping
: no hosts matched


...where "dummy" is the hosts entry in the playbook file. The playbook file looks like this:

- hosts: dummy
  become
: yes
  roles
:
   
- role: base
   
- role: ntp
      ntp_server
: [10.10.10.11, 10.10.10.12, 10.20.10.11]
      ntp_restrict
:
       
- "restrict 127.0.0.1"

How do I force a host on the command line without needing to define it in the playbook file or in the inventory? I'm on OSX 10.10.5 and Ansible 1.9.2.

Thanks!

-Pete

Brian Coca

unread,
Aug 19, 2015, 2:29:40 PM8/19/15
to Ansible Project
-i 'dummy,' -e 'ansible_ssh_host=<whatever>'
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/adc5edde-0542-4ed6-9c4a-3f227a8a6f48%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca

Serge van Ginderachter

unread,
Aug 19, 2015, 5:29:13 PM8/19/15
to ansible...@googlegroups.com

On 19 August 2015 at 20:28, Peter Loron <peter...@gmail.com> wrote:

> ansible-playbook -i '10.10.10.155,' -u root  do_base_packages.yaml


PLAY
[dummy] ******************************************************************
skipping
: no hosts matched


...where "dummy" is the hosts entry in the playbook file. The playbook file looks like this:

- hosts: dummy
  become
: yes
  roles
:
   
- role: base
   
- role: ntp
      ntp_server
: [10.10.10.11, 10.10.10.12, 10.20.10.11]
      ntp_restrict
:
       
- "restrict 127.0.0.1"

​anogther option is​:

- ​hosts: all​
Reply all
Reply to author
Forward
0 new messages