ansible之二:模块用法
一:ansible远程执行命令
[root@ansible ~]# ansible test -m shell -a "date"
192.168.0.28 | SUCCESS | rc= >>
2016年 08月 02日 星期二 :: CST
[root@ansible ~]# ansible test -m raw -a "date"
192.168.0.28 | SUCCESS | rc=0 >>
2016年 08月 02日 星期二 15:06:21 CST
[root@ansible ~]# ansible test -m command -a "date"
192.168.0.28 | SUCCESS | rc= >>
2016年 08月 02日 星期二 :: CST test为主机组名 -m后面跟模块名 -a后面跟命令 ,shell raw模块支持管道 command模块不支持
二:ansible拷贝文件或目录
[root@ansible ~]# ansible test -m copy -a "src=/data/shell/ dest=/data/shell/ "
192.168.0.28 | SUCCESS => {
"changed": true,
"dest": "/data/shell/",
"src": "/data/shell"
}
三:ansible远程执行脚本
首先创建一个shell脚本
vim /tmp/test.sh //加入内容
#!/bin/bash
echo `date` > /tmp/ansible_test.txt
然后把该脚本分发到各个机器上
ansible test -m copy -a "src=/tmp/test.sh dest=/tmp/test.sh mod=0755"
最后是批量执行该shell脚本
ansible test -m shell -a "/tmp/test.sh"
shell模块,还支持远程执行命令并且带管道ansible test-m shell -a "cat /etc/passwd|wc -l "
四:ansible安装rpm包/管理服务
[root@ansible ~]# ansible test -m yum -a "name=glances state=installed" //这里的name是centos系统里的服务名。
192.168.0.28 | SUCCESS => {
"changed": true,
五:ansible 同步模块synchronize 使用
功能: 数据同步管理 使用此模块需要服务端与web组都安装了rsync.
#ansible test -m shell -a "rpm -qa rsync" 检查是否安装了rsync
192.168.0.28 | SUCCESS | rc=0 >>
rsync-3.0.9-17.el7.x86_64
安装rsync
#ansible test -m shell -a "yum install -y rsync"
同步目录:
#ansible test -m synchronize -a "src=/data/adminshell/ dest=/data/adminshell/ "
同步目录,删除目的目录中源目录中没有的文件
#ansible test -m synchronize -a "src=/data/adminshell/ dest=/data/adminshell/ delete=yes"
"msg": "*deleting test.txt\n"
同步目录,排除某个文件
ansible test -m synchronize -a "src=/data/adminshell/ dest=/data/adminshell/ rsync_opts="--exclude=exclude.txt" "
同步目录,排除多个文件
ansible test -m synchronize -a "src=/data/adminshell/ dest=/data/adminshell/ rsync_opts="--exclude=\*.conf,--exclude=\*.html,--exclude=test1" "
#ansible-doc -s synchronize 模块用法
六:ping模块,检测主机是否存活。
[root@ansible ~]# ansible test -m ping //如果ansible 后面跟all ,则表示检测 hosts 文件中所有的服务器是否存活!
192.168.0.28 | SUCCESS => {
"changed": false,
"ping": "pong"
}
ansible之二:模块用法的更多相关文章
- Ansible系列(二):选项和常用模块
html { font-family: sans-serif } body { margin: 0 } article,aside,details,figcaption,figure,footer,h ...
- ansible常用模块用法
ansible常用模块用法 2015-07-21 10:25 24458人阅读 评论(1) 收藏 举报 分类: Linux(44) ansible 版权声明:本文为博主原创文章,未经博主允许不得 ...
- 二、Ansible基础之模块篇
目录 1. Ansible Ad-Hoc 命令 1.1 命令格式 1.2 模块类型 1.3 联机帮助 1.3.1 常用帮助参数 1.4 常用模块 1.4.1 command & shell 模 ...
- 运维自动化神器ansible之group模块
ansible之group模块 group模块是用来添加或者删除组 首先使用ansible-doc来查看用法 [root@note0 ansible]# ansible-doc -s group - ...
- ansible 四常用模块
常用模块 Ansible默认提供了很多模块来供我们使用.在Linux中,我们可以通过 ansible-doc -l 命令查看到当前Ansible支持哪些模块,通过 ansible-doc -s [模块 ...
- python笔记之常用模块用法分析
python笔记之常用模块用法分析 内置模块(不用import就可以直接使用) 常用内置函数 help(obj) 在线帮助, obj可是任何类型 callable(obj) 查看一个obj是不是可以像 ...
- nodeJS---URL相关模块用法(url和querystring)
nodeJS---URL相关模块用法(url和querystring) 一: URL模块: URL模块用于解析和处理URL的字符串,提供了如下三个方法: 1. parse 2. format 3. r ...
- ansible中常用模块详解
ansible中常用的模块详解: file模块 ansible内置的可以查看模块用法的命令如下: [root@docker5 ~]# ansible-doc -s file - name: Sets ...
- ansible初识二
一.ansible模块(yum.pip.service.conr.user.group) 上篇中我们已经学了ansible 的几个模块, 接下来再来学习几个, 那么你是否知道ansible 一共有多少 ...
随机推荐
- Caused by: org.h2.jdbc.JdbcSQLException: Table "T_STUDENT_INFO" not found; SQL statement
1.错误描述 org.hibernate.exception.SQLGrammarException: error executing work at org.hibernate.exception. ...
- web开发性能优化---代码优化篇
1.合理使用缓存使用 提高性能最好最快的办法当然是通过缓存来改善,对于任何一个web开发者都应该善用缓存.Asp.net下的缓存机制十分强大,用好缓存机制可以让我们极大的改善web应用的性能. 1.页 ...
- vue的ajax请求之axios
axios.get(this.apiUrl+'good/info',{params:{'goodsid':'sp441153'}}) .then(function(response){ console ...
- eclipse - The superclass "javax.servlet.http.HttpServlet" was not found on the Java
- Python爬虫 股票数据爬取
前一篇提到了与股票数据相关的可能几种数据情况,本篇接着上篇,介绍一下多个网页的数据爬取.目标抓取平安银行(000001)从1989年~2017年的全部财务数据. 数据源分析 地址分析 http://m ...
- [BZOJ1016] [JSOI2008] 最小生成树计数 (Kruskal)
Description 现在给出了一个简单无向加权图.你不满足于求出这个图的最小生成树,而希望知道这个图中有多少个不同的最小生成树.(如果两颗最小生成树中至少有一条边不同,则这两个最小生成树就是不同的 ...
- 纯css实现图片的灯光照射效果,高逼格图片展示
先不说技术,看实现的效果, 与原图(左图)相比,‘灯光’ 照射(右图)下的小姐姐是不是更有魅力了!! 那么下面就说说大家关心的技术实现过程. 其实这是我在学习css属性 mix-blend-mode ...
- 异步解决方案promise及源码实现
js语言的特性,造就了特别的异步处理方式,我记得以前用的最多的就是回调函数,那个时候写jquery的ajax时候,特别喜欢写这种代码: $.ajax({ method:'get', url:" ...
- 封装好的MD5加密
/** * 不可逆加密类 为密码提供不可逆的加密运算,使用MD5算法 * * 使用方法: MD5 encrypt = new MD5(); encrypt.getMD5ofStr(str); //返回 ...
- NYOJ 题目12喷水装置(二)
#include<iostream> #include<algorithm> #include<cmath> using namespace std; struct ...