Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use an inventory file for Ansible ad-hoc commands?

Ansible v2.2.1.0

I want to gather Ansible facts about a remote host defined in my inv/remote_hosts file, which looks like this:

[remote-host-0]
10.22.123.234

[remote-host-1]
10.22.234.123

How do I run the setup command and tell it to gather facts for remote-host-0?

$ ansible ??? -m setup ???

If I simply do this:

$ ansible remote-host-0 -m setup

I get:

ERROR! Attempted to read "/path_to_my_ansible_dir/ansible//hosts" as YAML: Syntax Error while loading YAML.

It's looking for the wrong hosts file, and I get a YAML error.

like image 903
Chris F Avatar asked Mar 22 '17 00:03

Chris F


1 Answers

You can specify an inventory file with the -i option:

ansible remote-host-0 -m setup -i inv/remote_hosts
like image 104
techraf Avatar answered Oct 19 '22 16:10

techraf