ansible 命令
原创
©著作权归作者所有:来自51CTO博客作者kq1983的原创作品,请联系作者获取转载授权,否则将追究法律责任
# ansible-doc 模块名称
ansible-doc shell
ansible-doc -s shell
#查看远程主机内存
ansible appservers -m command -a "free -m"
# -m 默认是command
ansible appservers -a free
#ping远程主机
ansible -m ping appservers
# -u 指定用户
ansible appservers -m ping -u bruce
#执行主控端的shell
ansible appservers -m script -a "/shell/freem.sh"
#执行被控端的shell
ansible appservers -m shell -a "/shell/freem.sh"
# command 执行远程权限范围所有的shell命令 管道不支持
# script 在远程主机执行主控端存储的shell脚步 相当于scp+shell组合
# shell功能是执行远程主机的shell脚本
# 从主控端 复制到被控端
ansible appservers -m copy -a 'src=/shell/copyfile dest=/shell backup=yes'
# 从被控端的的日志/tmp/my.log 放到主控端的/tmp目录
ansible appservers -m fetch -a 'src=/tmp/my.log dest=/tmp'
# 相当于 mkdir -p
ansible appservers -m file -a "dest=/path/to/c mode=755 state=directory"
#创建用户
ansible all -m user -a "name=mytest password=123456"
# -b sudo以root权限执行
ansible appservers -b -a "tail /var/log/dmesg"
#查看文件分区
ansible appservers -a 'df -h'
# chdir 切换目录
ansible appservers -a 'chdir=/tmp pwd'
ansible appservers -a 'getent passwd root'
ansible appservers -a 'getenforce'
# 卸载httpd
ansible appservers -m yum -a 'name=httpd state=removed'
ansible testservers -m service -a "name=docker state=started"