1、查看ansible控制主机
[ansible@control ansible]$ ansible all --list
2、ansible使用方式
(1)ansible ad-hoc 任务量较小时使用
(2)ansible playbook 任务量较多时使用
3、ansible命令格式
ansible 被控主机 -m 指定功能模块 -a 传递的参数
[ansible@control ansible]$ ansible node1 -m command -a 'touch /home/hello' 在被控主机创建文件
红色非报错,只是提示有更适合的模块,下面金黄色,node1表示执行主机,changed表示已经按命令更改,rc=0,返回值为0表示执行成功,在node1主机上查看
已经成功在home目录下创建hello文件
[ansible@control ansible]$ ansible all -m command -a 'ls /home/hello' 进行查看
在ansible中,红色和FAILED一般表示失败,金色CHANGED表示执行成功
command是默认模块,可以不写
[ansible@control ansible]$ ansible node1 -a 'echo 123 > /home/hello'
发现commod模块执行命令不支持重定向
[ansible@control ansible]$ ansible node1 -m shell -a 'echo 123 > /home/hello'
可以使用shell模块,功能和command类似,但是支持重定向和管道符