Think before you speak, read before you think.

ansible直接通过ip操作机器

如果要了解一两个 ip 的一些简单的情况如 ls -l /data0/ | wc -l,以前是要写到文件里的。

ansible -i hosts all -m shell -a "ls -l /data0/ | wc -l"

也可以这样,一台机器最后面要有一个逗号

ansible all -i 192.168.1.1, -m shell -a "ls -l /data0/ | wc -l"

两台机器用逗号隔开,并且不能有空格

ansible all -i 192.168.1.1,192.168.1.2 -m shell -a "ls -l /data0/ | wc -l"

参考: http://stackoverflow.com/questions/17188147/how-to-run-ansible-without-specifying-the-inventory-but-the-host-directly?answertab=votes#tab-top

题外话:

除了上面的 shell 模块,还有 command, script 可以在被管理机器上方便执行 shell.

ansible all -i hosts -l 192.168.1.183 -m script -a uptime.sh

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *