如何在没有hosts文件的情况下运行Ansible

guo*_*oya 11 shell ansible

如何在没有hosts文件的情况下运行Ansible

就像:

__CODE__

谢谢

Arb*_*zar 19

你可以这样做:

ansible all -i "<hostname-or-ip>," -a 'uptime'
Run Code Online (Sandbox Code Playgroud)

请注意,IP地址末尾,或者它将被视为主机库存文件名.

以下是一个参考示例:

ansible all -i "192.168.33.100," -a 'uptime'

192.168.33.100 | SUCCESS | rc=0 >>
 12:05:10 up 10 min,  1 user,  load average: 0.46, 0.23, 0.08
Run Code Online (Sandbox Code Playgroud)


Nas*_*asr 5

可以使用三种方式将主机分配给ansible

从中ansible --help可以获得-i选项说明

-i INVENTORY, --inventory-file=INVENTORY
                    specify inventory host path
                    (default=/etc/ansible/hosts) or comma separated host
                    list.
Run Code Online (Sandbox Code Playgroud)