[Errno 2] No such file or directory

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
posted @ 2019-02-26 18:42  吕涵之  阅读(5463)  评论(0编辑  收藏  举报