command
# 执行系统命令,不支持命令中带特殊字符 <> | ; & 等
ansible localhost -m command -a 'ls /root'
ansible localhost -m command -a 'chdir=/tmp creates=1.txt ls'
# chdir 执行目录
# creates 判定条件,文件存在则不执行,文件不存在则执行
# remove 判定条件,文件存在则执行,文件不存在则不执行
# 不能使用自定义变量
# 查看文档
# ansible-doc command -s
shell
# command 升级版,支持特殊字符
ansible localhost -m shell -a 'ls /root >> /tmp/root.txt'
ansible localhost -m shell -a '/bin/bash /tmp/test.sh nihao'
# 查看文档
# ansible-doc shell -s
script
# 拷贝 shell 脚本到目标主机并执行
ansible localhost -m script 'executable=/bin/bash /tmp/test.sh'