ansible shell模块主要用于远程客户端上执行各种shell命令或运行脚本,远程执行命令通过/bin/sh环境来执行,支持比command更多的指令,shell模块使用详解:
chdir 执行命令前,切换到目录; creates 当该文件存在时,则不执行该步骤; executable 换用shell环境执行命令; free_form 需要执行的脚本; removes 当该文件不存在时,则不执行该步骤; warn 如果在ansible.cfg中存在告警,如果设定了False,不会警告此行;1.ansible shell模块操作-客户端执行shell脚本
ansible all -m shell -a "/bin/sh /root/filesystem_used.sh >> /tmp/var.log"-m shell指定模块为shell,远程执行shell脚本(shell脚本要部署在客户端服务器),远程执行脚本也可采用script模块,并把执行结果追加至客户端服务器/tmp/var.log文件。
Ansible Server
[root@cent79-2 ~]# ansible all -m shell -a "/bin/sh /root/filesystem_used.sh >> /tmp/var.log" 192.168.10.100 | CHANGED | rc=0 >> [root@cent79-2 ~]#Client
[root@patrolagent tmp]# pwd /tmp [root@patrolagent tmp]# cat var.log filesystem_name=