Ansible 模块命令介绍
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 模块命令介绍的更多相关文章
- ansible模块的介绍与使用
ansible-doc的使用 1.ansible-doc -h可以看见ansible-doc的所有参数 2.ansible-doc 命令格式:ansible-doc [-l|-F|-s] [optio ...
- 【Ansible 文档】【译文】Ad-Hoc 命令介绍
Introduction To Ad-Hoc Commands Ad-Hoc命令介绍 下面的例子展示了如何使用 /usr/bin/ansible 来运行ad hoc任务. 什么是ad hoc命令? 一 ...
- Ansible常用模块命令
Ansible常用模块命令 一.安装ansible yum install epel-release yum install ansible 二.配置文件配置 vi /etc/ansible/ansi ...
- 004.Ansible Ad-Hoc命令集
一 Ad-Hoc使用场景 Ad-Hoc更倾向于解决简单.临时性任务. 1.1 Ad-Hoc基础命令 基本语法: 1 ansible <host-pattern> [options] < ...
- ansible模块之yum、pip、service、corn、user、group
ansible相关模块 yum rpm 和yum 的区别 rpm:全称redhat package manager (红帽包管理器) 不能解决包之间的依赖关系 yum:可以解决依赖关系 yum 源配置 ...
- centos ansible常用命令
ansible在日常运维中经常使用,特别是批量执行多台服务器的时候,有效减小重复的操作成本,以下从安装到使用仅讲解工作中常用的几种方式,模块很多功能很强大,但不做全面讨论. ansible安装 在ce ...
- ansible模块
ansible模块: 模块(Modules),类似于 "任务插件"("task plugins")或"库插件"("library ...
- Ansible自动化运维笔记2(Ansible的组件介绍)
1.Ansible Inventory (1)静态主机文件 默认的ansible invetory是/etc/hosts文件,可以通过ANSIBLE_HOSTS环境变量或者通过运行命令的时候加上-i ...
- ansible常用命令
一.ansible常用命令 一.ansible命令的常用参数 ansible 默认提供了很多模块来供我们使用.在 Linux 中,我们可以通过 ansible-doc -l 命令查看到当前 ansib ...
随机推荐
- js函数表达式和函数声明的区别
我们已经知道,在任意代码片段外部添加包装函数,可以将内部的变量和函数定义"隐 藏"起来,外部作用域无法访问包装函数内部的任何内容. 例如: var a = 2; function ...
- 利用django创建一个投票网站(一)
这是教程的原始链接:http://django-intro-zh.readthedocs.io/zh_CN/latest/part1/ 创建你的第一个 Django 项目, 第一部分 来跟着实际项目学 ...
- Ubuntu学习总结-10 XManager
最近接触到一个很有意思的实验,在这里与大家分享,实验目标在Window显示UBuntu程序. 1 测试环境: Windows8的IP地址 : 192.168.7.126 UBuntu16的IP地址 : ...
- ThinkPhp 3.2 自动验证
自动验证是ThinkPHP模型层提供的一种数据验证方法,可以在使用create创建数据对象的时候自动进行数据验证. 数据验证有两种方式: 静态方式:在模型类里面通过$_validate属性定义验证规则 ...
- bootstrap学习笔记--bootstrap排版类的使用
标题 Bootstrap 中定义了所有的 HTML 标题(h1 到 h6)的样式,这个和一般的html没啥区别.请看下面的实例: <h1>测试1 h1</h1> <h2& ...
- C#可用的日出日落时间类
一个现成代码的公共类库,复制下来作为一个类文件就可以调用了.一般不需要了解实现过程,各种数学公式太麻烦. 调用方法: SunTimeResult result = SunTimes.GetSunTim ...
- oracle 12c 加入系统服务
1修改oratab文件 vi /etc/oratab #把后台一行的N改为Y db01:/usr/oracle/app/product/11.2.0/dbhome_1:Y 2如果安装时.bash_pr ...
- Could not find or load main class org.gradle.wrapper.GradleWrapperMain解决办法
解决办法: gradlew is the gradle wrapper executable - batch script on windows and shell script elsewhere. ...
- (一)SQL Server分区详解Partition(目录)
一.SQL Server分区介绍 在SQL Server中,数据库的所有表和索引都视为已分区表和索引,默认这些表和索引值包含一个分区:也就是说表或索引至少包含一个分区.SQL Server中数据是按水 ...
- Linux各个目录的作用及内容
1)根目录“/” 根目录位于目录结构的最顶层,用斜线(/)表示,类似于Windows操作系统的“C:\“,包含Fedora操作系统中所有的目录和文件. 2)/bin /bin 目录又称为二 ...