模块的应用语法格式:
ansible 主机名称/主机组名称/主机地址信息/all -m(指定应用的模块信息) 模块名称 -a(指定动作信息) "执行什么动作"
命令类型模块:
掌握第一个模块: command (默认模块)
command – Executes a command on a remote node
在一个远程主机上执行一个命令
简单用法:
[root@m01 scripts]# ansible 172.16.1.31 -m command -a "hostname"
172.16.1.31 | CHANGED | rc=0 >>
nfs01
扩展应用:
1) chdir Change into this directory before running the command.
在执行命令之前对目录进行切换
ansible 172.16.1.31 -m command -a "chdir=/tmp touch oldboy.txt"
2) creates If it already exists, this step won't be run.
如果文件存在了,不执行命令操作
ansible 172.16.1.31 -m command -a "creates=/tmp/hosts touch oldboy.txt"
3) removes If it already exists, this step will be run.
如果文件存在了, 这个步骤将执行