- 查看可使用的模块
- [root@aliyun-63 ~]# ansible-doc -l
- 查看帮助
- [root@aliyun-63 ~]# ansible-doc -s yum
- 1.setup模块
- 功能:收集系统信息
- [root@aliyun-63 ~]# ansible 118 -m setup
- 2.ping 模块
- 功能:检测远程主机是否存活
- [root@aliyun-63 ~]# ansible 118 -m ping
- 3.file 模块
- 功能:新建 删除 目录 文件
- value of state must be one of: file,directory,link,hard,touch,absent
- [root@aliyun-63 ~]# ansible 118 -m file -a "path=/tmp/2 state=touch"
- [root@aliyun-63 ~]# ansible 118 -m file -a "path=/tmp/3 state=directory"
- [root@aliyun-63 ~]# ansible 118 -m file -a "path=/tmp/3 state=absent"
- 4.copy 模块
- 功能:本地文件复制到远程主机群,进行统一部署
- [root@aliyun-63 ~]# ansible 118 -m copy -a "src=/tmp/63_gcnew.log dest=/tmp/63_gcnew.log mode=600"
- [root@aliyun-63 ~]# ansible 118 -m copy -a "src=/tmp/63_gcnew.log dest=/tmp/63_gcnew.log backup=yes"
- 5.command 模块
- 功能:远程执行一个命令 如 ls cat
- [root@aliyun-63 ~]# ansible 118 -m command -a 'creates=/tmp/linuser.txt ls -l /etc/passwd'
- creates 前面成立 后面不执行
- removes 前面不成立 后面执行
- chdir 切换目录
- [root@aliyun-63 ~]# ansible 118 -m command -a 'chdir=/tmp ls '
- 6.shell 模块
- 功能:command 模块不支持管道命令的执行 它支持
- [root@aliyun-63 ~]# ansible 118 -m shell -a 'cat /tmp/63_gcnew.log | grep 2016'
- 7.yum 模块
- 功能: 安装 或者 卸载 软件包
- [root@aliyun-63 ~]# ansible 118 -m yum -a 'name=lrzsz state=installed'
- [root@aliyun-63 ~]# ansible 118 -m yum -a 'name=lrzsz state=removed'
- 8.service 模块
- 功能: 对某些服务的启动、重启、停止、重载等的管理
- [root@aliyun-63 ~]# ansible 118 -m yum -a 'name=redis state=installed'
- [root@aliyun-63 ~]# ansible 118 -m service -a 'name=redis state=started enabled=yes'
- [root@aliyun-63 ~]# ansible 118 -m shell -a 'netstat -lnp | grep redis'
- 9.cron 模块
- 功能: 建立计划任务
- [root@aliyun-63 ~]# ansible 118 -m cron -a "name='restart nginx' hour=11 user=root job='/opt/nginx/sbin/nginx -s reload'"
- [root@aliyun-63 ~]# ansible 118 -m shell -a "crontab -l | tail -2"
- 10.user 模块
- 功能: 管理用户的模块
- [root@aliyun-63 ~]# ansible 118 -m user -a 'name=ddd state=present '
- [root@aliyun-63 ~]# ansible 118 -m user -a 'name=ddd state=absent '
- 11.synchronize 模块
- 功能: 数据同步管理
- [root@aliyun-63 yum.repos.d]# ansible 118 -m yum -a "name=rsync state=installed"
- [root@aliyun-63 sd]# ansible 118 -m synchronize -a 'src=/tmp/sd dest=/tmp/ mode=push delete=yes'
- [root@aliyun-63 sd]# ansible 118 -m synchronize -a 'src=/tmp/sd dest=/tmp/ mode=push delete=yes rsync_opts="-avz,--exclude=Test"'
- 最新活动: 2016-09-07 14:41
- 浏览: 1126
- 关注: 0 人
编辑回复