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 ...
随机推荐
- 【BZOJ 1494】【NOI 2007】生成树计数
http://www.lydsy.com/JudgeOnline/problem.php?id=1494 这道题..因为k很小,而且我们只关心连续的k个节点的连通性,所以把连续的k个点轮廓线上的连通性 ...
- Mysql触发器
触发器(trigger)作用:监视某种情况,并触发某种操作. 触发器创建语法四要素: 1.监视地点(table) 2.监视事件(insert/update/delete) 3.触发时间(after/b ...
- 小猪cms模块继承
TextAction 继承 UserAction 继承 BaseAction 继承 Action TextAction 路径 PigCms\Lib\Action\User UserAction 路径 ...
- .net 项目生成时自动更新版本号
https://www.codeproject.com/articles/31236/how-to-update-assembly-version-number-automaticall Exampl ...
- linux文件目录结构
1./ 文件系统的入口,最高一级目录 2./bin 存放基础系统所需的命令 3./boot 包含Linux内核及系统引导程序所需要的文件 4./dev 设备文件存储目录(声卡.磁盘.分区..) 5./ ...
- C#基础练习
1.冒泡排序 namespace _0 { class Program { public static int[] BubbleSort(int[] arr) { ; i < arr.Lengt ...
- 利用BitMap进行大数据排序去重
1.问题 问题提出: M(如10亿)个int整数,只有其中N个数重复出现过,读取到内存中并将重复的整数删除. 2.解决方案 问题分析: 我们肯定会先想到在计算机内存中开辟M个int整型数据数组,来on ...
- UI
http://semantic-ui.com/introduction/getting-started.html
- 回顾Spirng ioc 控制反转
Spring的IoC(控制反转) .DI(依赖注入)这两个概念,对于初学Spring的人来说,总觉得IoC .DI这两个概念是模糊不清的,是很难理解的.结合网上对Spring Ioc的理解,回顾一下自 ...
- SpringMVC学习记录2
废话 最近在看SpringMVC...里面东西好多...反正东看一点西看一点吧... 分享一下最近的一些心得..是关于DispatcherServlet的 DispatcherServlet与Cont ...