ansible的三个命令模块:command、shell、raw,这三个模块的参数就直接输入命令即可。 1: 、ansible模块command (不支持管道,不建议使用) ansible nginx -m command -a "ifconfig ens33"ansible nginx -m command -a "df -hT"
ansible all -m command -a "df -h|grep tmpfs" #不支持管道
ansible nginx -m command -a "df -hT >/tmp/a.txt" #不支持重定向
2: 、ansible模块shell (支持管道) ansible nginx -m shell -a "df -h|grep dev" #支持管道
ansible nginx -m shell -a "df -h|grep dev >/tmp/a.txt" #支持重定向
ansible nginx -m shell -a "ifconfig ens33|awk -F '[ :]+' 'NR==2 {print \$3}'" #特殊字符需要转义
3: 、ansible模块raw,最原始ssh的方式运行命令 此模块的执行,在远程主机上,不需要python环境,主要使用raw的原因是,老版本的python中,那么就需要用raw;如果客户端是路由器的话,那么就必须要使用raw模块 ,raw很多地方和shell和command相似,更多推荐的地方使用的是shell和command模块 ansible nginx -m raw -a "yum install vsftpd -y"