copy模块:

目的:把主控端/root目录下的a.sh文件拷贝到到指定节点上

命令:ansible 10.1.1.113 -m copy -a 'src=/root/a.sh dest=/tmp/'

file模块:

目的:更改指定节点上/tmp/t.sh的权限为755,属主和属组为root

命令:ansible all -m file -a "dest=/tmp/t.sh mode=755 owner=root group=root"

cron模块:

目的:在指定节点上定义一个计划任务,每隔3分钟到主控端更新一次时间

命令:ansible all -m cron -a 'name="custom job" minute=*/3 hour=* day=* month=* weekday=* job="/usr/sbin/ntpdate 172.16.254.139"'

group模块:

目的:在所有节点上创建一个组名为nolinux,gid为2014的组

命令:ansible all -m group -a 'gid=2014 name=nolinux'

user模块:

目的:在指定节点上创建一个用户名为nolinux,组为nolinux的用户

命令:ansible 10.1.1.113 -m user -a 'name=nolinux groups=nolinux state=present'

yum模块:

目的:在指定节点上安装 lrzsz 服务

命令:ansible all -m yum -a "state=present name=httpd"

service模块:

目的:启动指定节点上的 puppet 服务,并让其开机自启动

命令:ansible 10.1.1.113 -m service -a 'name=puppet state=restarted enabled=yes'

script模块:

目的:在指定节点上执行/root/a.sh脚本(该脚本是在ansible控制节点上的)

命令:ansible 10.1.1.113 -m script -a '/root/a.sh'

ping模块:

目的:检查指定节点机器是否还能连通

命令:ansible 10.1.1.113 -m ping

command模块:

目的:在指定节点上运行hostname命令

命令:ansible 10.1.1.113 -m command -a 'hostname'

raw模块:

目的:在10.1.1.113节点上运行hostname命令

命令:ansible 10.1.1.113 -m raw-a 'hostname|tee'

get_url模块:

目的:将http://10.1.1.116/favicon.ico文件下载到指定节点的/tmp目录下

命令:ansible 10.1.1.113 -m get_url -a 'url=http://10.1.1.116/favicon.ico dest=/tmp'

synchronize模块:

目的:将主控方/root/a目录推送到指定节点的/tmp目录下

命令:ansible 10.1.1.113 -m synchronize -a 'src=/root/a dest=/tmp/ compress=yes'

执行效果:

delete=yes   使两边的内容一样(即以推送方为主)

compress=yes  开启压缩,默认为开启

--exclude=.Git  忽略同步.git结尾的文件

由于模块,默认都是推送push。因此,如果你在使用拉取pull功能的时候,可以参考如下来实现

mode=pull   更改推送模式为拉取模式

目的:将10.1.1.113节点的/tmp/a目录拉取到主控节点的/root目录下

命令:ansible 10.1.1.113 -m synchronize -a 'mode=pull src=/tmp/a dest=/root/'

执行效果:

由于模块默认启用了archive参数,该参数默认开启了recursive, links, perms, times, owner,group和-D参数。如果你将该参数设置为no,那么你将停止很多参数,比如会导致如下目的递归失败,导致无法拉取

Ansible 模块命令介绍的更多相关文章

  1. ansible模块的介绍与使用

    ansible-doc的使用 1.ansible-doc -h可以看见ansible-doc的所有参数 2.ansible-doc 命令格式:ansible-doc [-l|-F|-s] [optio ...

  2. 【Ansible 文档】【译文】Ad-Hoc 命令介绍

    Introduction To Ad-Hoc Commands Ad-Hoc命令介绍 下面的例子展示了如何使用 /usr/bin/ansible 来运行ad hoc任务. 什么是ad hoc命令? 一 ...

  3. Ansible常用模块命令

    Ansible常用模块命令 一.安装ansible yum install epel-release yum install ansible 二.配置文件配置 vi /etc/ansible/ansi ...

  4. 004.Ansible Ad-Hoc命令集

    一 Ad-Hoc使用场景 Ad-Hoc更倾向于解决简单.临时性任务. 1.1 Ad-Hoc基础命令 基本语法: 1 ansible <host-pattern> [options] < ...

  5. ansible模块之yum、pip、service、corn、user、group

    ansible相关模块 yum rpm 和yum 的区别 rpm:全称redhat package manager (红帽包管理器) 不能解决包之间的依赖关系 yum:可以解决依赖关系 yum 源配置 ...

  6. centos ansible常用命令

    ansible在日常运维中经常使用,特别是批量执行多台服务器的时候,有效减小重复的操作成本,以下从安装到使用仅讲解工作中常用的几种方式,模块很多功能很强大,但不做全面讨论. ansible安装 在ce ...

  7. ansible模块

    ansible模块: 模块(Modules),类似于 "任务插件"("task plugins")或"库插件"("library ...

  8. Ansible自动化运维笔记2(Ansible的组件介绍)

    1.Ansible Inventory (1)静态主机文件 默认的ansible invetory是/etc/hosts文件,可以通过ANSIBLE_HOSTS环境变量或者通过运行命令的时候加上-i ...

  9. ansible常用命令

    一.ansible常用命令 一.ansible命令的常用参数 ansible 默认提供了很多模块来供我们使用.在 Linux 中,我们可以通过 ansible-doc -l 命令查看到当前 ansib ...

随机推荐

  1. ajax同步处理(使得JS按顺序执行)

    在项目中碰到一个问题: 图一: 图二: 函数1代码:这里是因为有ajax请求,默认的是异步的 //点击分页页码,请求后台返回对应页码的数据 function getdata(fewPage,flag, ...

  2. form表单提交时,action怎么带参数

    <html> <title>form</title> <script type="text/javascript"> functio ...

  3. .net 项目生成时自动更新版本号

    https://www.codeproject.com/articles/31236/how-to-update-assembly-version-number-automaticall Exampl ...

  4. Linux服务器SSH无密码访问

    1.编辑Hosts文件: [root@yqtrack-elk01 /]# vim /etc/hosts

  5. 深入浅出 Redis client/server交互流程

    综述 最近笔者阅读并研究redis源码,在redis客户端与服务器端交互这个内容点上,需要参考网上一些文章,但是遗憾的是发现大部分文章都断断续续的非系统性的,不能给读者此交互流程的整体把握.所以这里我 ...

  6. 如何生成每秒百万级别的 HTTP 请求?

    第一篇:<如何生成每秒百万级别的 HTTP 请求?> 第二篇:<为最佳性能调优 Nginx> 第三篇:<用 LVS 搭建一个负载均衡集群> 本文是构建能够每秒处理 ...

  7. js loaclstorage和sessionstorage

    这里需要注意的是这两种储存方式只能以字符串的形式来存取 html5中的Web Storage包括了两种存储方式:sessionStorage和localStorage.sessionStorage用于 ...

  8. 12月5日PHPCMS替换主页

    cms替换主页的步骤 1.先做好静态页面: 2.在D:\wamp\www\phpcms\install_package\phpcms\templates文件夹下建新的文件夹tianqiwangluo( ...

  9. net.sf.json.JSONException: There is a cycle in the hierarchy!的解决办法

    使用Hibernate manytoone属性关联主表的时候,如果使用JSONArray把pojo对象转换成json对象时,很容易出现循环的异常.解决的办法就是, 在转换json对象时忽略manyto ...

  10. String字符串针对常量池的优化

    String对象是java语言中重要的数据类型,但是不是基本数据类型.相对于c语言的char java做了一些封装和延伸. 针对常量池的优化:当两个String拥有相同的值时,它们只引用常量池中的同一 ...