ansible模块
ansible模块:
模块(Modules),类似于 “任务插件“(”task plugins”)或“库插件”(“library plugins”)的东西。
模块 可以单独的被ansible命令调用;也可以在palybook的每个任务中被执行。
每个模块都能接收参数(arguments),绝大部分arguments的格式是key=value,用空格隔开。
一些如 ansible servers -m command -a "/sbin/reboot -t now",不是key=value格式,而是直接传shell命令。
命令行调用:
ansible webservers -m service -a "name=httpd state=started"
ansible webservers -m ping
ansible webservers -m command -a "/sbin/reboot -t now"
命令行中的-m表示调用哪个模块,-a表示模块的参数(arguments)。
palybook中调用:
- name: reboot the servers
action: command /sbin/reboot -t now
- name: reboot the servers
command: /sbin/reboot -t now // 可省略action,等同于action: command
- name: restart webserver
service: name=httpd state=restarted
也可以用yaml的语法传入参数:
- name: restart webserver
service:
name: httpd
state: restarted
所以的模块都有统一的json格式的返回值。
模块是等幂的
避免使用模块改变,模块必须是幂等的(idempotent,不改变的)???
模块会尽可能避免对系统作出改动,除非必须要改动的时候。
当使用playbooks时, 模块能够触发 ‘change events’,触发后会通知 ‘handlers’ 去运行附加任务。
了解模块的方法:
ansible-doc 模块名称 , ansible-doc -l列出所有模块。
常用模块:
setup 查看主机的一些基本信息
ping 测试主机的运行状态
file 文件操作
copy 复制文件到主机
command 在主机上执行命令
shell 切换到shell,执行指定的指令
其他模块:
service:系统服务管理
cron:计划任务管理
yum:yum软件包安装管理
synchronize:使用rsync同步文件
user:系统用户管理
group:系统用户组管理
统一返回值
- backup_file
- changed
- failed
- invocation
- msg
- rc
- results
- skipped
- stderr
- stderr_lines
- stdout
- stdout_lines
ansible模块的更多相关文章
- ansible笔记(3):ansible模块的基本使用
ansible笔记():ansible模块的基本使用 在前文的基础上,我们已经知道,当我们使用ansible完成实际任务时,需要依靠ansible的各个模块,比如,我们想要去ping某主机,则需要使用 ...
- 第4天:Ansible模块
Ansible对远程服务器的实际操作实际是通过模块完成的,其工作原理如下: 1)将模块拷贝到远程服务器 2)执行模块定义的操做,完成对服务器的修改 3)在远程服务器中删除模块 需要说明的是,Ansib ...
- ansible模块command、shell、raw、script
简介 环境: ansible端: ip:192.168.100.129 hostname:node1.lansgg.com client端: ip:192.168.100.131 hostname:v ...
- win10的pycharm中安装ansible模块过程
前面的安装报错信息 ansible模块安装报错:Could not install packages due to an OSError: [Errno 2] No such file or dire ...
- Ansible 模块命令介绍
copy模块: 目的:把主控端/root目录下的a.sh文件拷贝到到指定节点上 命令:ansible 10.1.1.113 -m copy -a 'src=/root/a.sh dest=/tmp/' ...
- ansible 模块 分享
A a10_server 管理A10 Networks AX / SoftAX / Thunder / vThunder设备 a10_service_group 管理A10网络设备的服务组 a10_v ...
- ansible 模块
1. #vim /etc/ansible/yaml/back.yml - hosts: siyi tasks: - name: "yum rsync" yum: name=rsyn ...
- ansible模块学习
ansible的功能: 模块化任务,调用特定的模块,完成特定的任务 基于python语言实现,由paramiko.pyyaml和jinja2三个模块构建 部署简单,agentless,ansible基 ...
- 4.1、Ansible模块
ansible-doc -l 列出所有模块 ansible-doc 模块名 查看模块的help说明 ansible-doc -s module_name:获取指定模块的使用信息 ***文 ...
随机推荐
- SQL Server 镜像
sql server 2005镜像制作 以下是操作步骤:-- =========================================== -- 无论是主体服务器.镜像服务器, 还是见证服务 ...
- MySQL Mysqlslap
在mysql5.1以后的版本:客户端带了个工具mysqlslap可以对mysql进行压力测试: 可以使用mysqlslap --help来显示使用方法: Default options are rea ...
- JWPlayer 初探
http://www.360doc.com/content/13/0103/22/21412_258041878.shtml JWPlayer 是一款比较实用的web flash 播放器
- 在python中编写socket服务端模块(二):使用poll或epoll
在linux上编写socket服务端程序一般可以用select.poll.epoll三种方式,本文主要介绍使用poll和epoll编写socket服务端模块. 使用poll方式的服务器端程序代码: i ...
- aliyun 镜像
[epel]name=Extra Packages for Enterprise Linux 6 - $basearchbaseurl=http://mirrors.aliyun.com/epel/6 ...
- python闭包以及装饰器
通俗的定义:如果在一个内部函数里,对在外部作用域(但不是在全局作用域)的变量进行引用,那么内部函数就被认为是闭包(closure).它只不过是个“内层”的函数,由一个名字(变量)来指代,而这个名字(变 ...
- ASP.NET -- repeater控件的使用
转载自网络-原网址[http://blog.csdn.net/haitaodoit/article/details/7021214] repeater绑定数据: protected void Page ...
- BSTR、char*和CString转换
(1) char*转换成CString 若将char*转换成CString,除了直接赋值外,还可使用CString::Format进行.例如: char chArray[] = "This ...
- MVC下载Excel
方法1: public ActionResult DownExcel() { var stream = list.Select(p => new { p.UserName, p.Mobile, ...
- JS字符串方法总结整理
//javascript字符串方法总结 1.String.charAt(n) //取得字符串中的第n个字符 2.String.charCodeAt(n) //取得字符串中第n个字符 ...