Centos7.5 執行ansible命令報錯
問題:
[root@m01 ~]# ansible servers -a "hostname|grep web" -i ./hosts
172.16.1.7 | FAILED | rc=2 >>
[Errno 2] No such file or directory
原因:
默認使用的是command模塊,command模塊不能使用管道
解決方法:
使用shell模塊執行命令
[root@m01 ~]# ansible servers -m shell -a "hostname|grep web" -i ./hosts
172.16.1.7 | CHANGED | rc=0 >>
web01