Ansible是一款简单的运维自动化工具,只需要使用ssh协议连接就可以来进行系统管理,自动化执行命令,部署等任务。

Ansible的特点

1、ansible轻量级无客户端agentless,只需要双方支持ssh

2、ansible playbook 采用yaml配置,对于自动化任务执行统一了脚本格式

3、学习成本低,快速上手

4、完整的模块化扩展,支持开发能容丰富

Ansible组成结构

Ansible
Ansible的命令工具,核心执行工具;一次性或临时执行的操作都是通过该命令执行。

Ansible Playbook
任务剧本(又称任务集),编排定义Ansible任务集的配置文件,由Ansible顺序依次执行,yaml格式。

Inventory
Ansible管理主机的清单,默认是/etc/ansible/hosts文件。

Modules
Ansible执行命令的功能模块,Ansible2.3版本为止,共有1039个模块。还可以自定义模块。

Plugins
插件,模块功能的补充,常有连接类型插件,循环插件,变量插件,过滤插件,插件功能用的较少。

API
提供给第三方程序调用的应用程序编程接口。



安装与快速使用 

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo  && yum clean all && yum makecache

yum -y install ansible

ansible --version

————————————————————————————————————————

配置主机Inventory     /etc/ansible/hosts

临时指定inventory   /etc/ansible-web

[root@C7-local ~]# cat /etc/ansible/hosts
# This is the default ansible 'hosts' file.
[web]
192.168.9.243
192.168.9.242
192.168.9.241

[db]
192.168.17.214
192.168.17.220
192.168.17.248

————————————————————————————————————————

查看主机列表  
ansible all --list-hosts
ansible web --list
ansible all -m ping -i /etc/ansible-web

查看主机存活状态
ansible web -m ping -o
匹配apache组nginx组两个组所有的机器(并集)
ansible 'web:db' -m ping -o 
执行非内置命令
ansible web -m shell -a 'yum clean all ; yum makecache' -o

Ansible Playbooks常用模块

file模块  在目标主机创建文件或目录,并赋予其系统权限

- name:create a file
file: 'path=/root/test.txt state=touch mode=0755
owner=user group=user'
 
copy模块  实现Ansible服务端到目标主机的文件传送
- name:copy a file
copy:'remote_src=no src=roles/testbox/files/test.sh
dest=/root/test.sh mode=0644 force=yes'
 
Stat模块    获取远程文件状态信息
- name:check if test.sh exists
stat: 'path=/root/test.sh'
register:script_stat
 
Debug模块    打印语句到Ansible执行输出
-debug:msg=test.sh exists
when:script_stat.stat.exists
 
Command/Shell模块    用来执行Linux目标主机命令行 
- name:run the script
command:"sh/root/test.sh"
-name:run the script
shell:"echo'test'>/root/test.txt"
 
Template模块    实现Ansible服务端到目标主机的jinja2模板传送
- name:write the nginx config file
   template:src=roles/testbox/templates/nginx.confj2
dest=/etc/nginx/nginx.conf
 
Packaging模块    调用目标主机系统包管理工具(yum,apt)进行安装
- name:ensure nginx is at the latest version 
yum:pkg=nginx state=latest
 
Service模块    管理目标主机系统服务
- name:start nginx service
service:name=nginx state=started
 
ansible-playbook -i inventory/testenv ./deploy.yml
 
 

Ansible-playbook执行慢

 gather_facts: no


PS:

Ansible快速入门

Ansible文献资料

Ansible中文权威指南

Ansible批量执行命令慢的解决思路

Ansible执行速度优化指北

Ansible-快速启动的更多相关文章

  1. ansible 快速入门

    安装 $ sudo apt-get install software-properties-common $ sudo apt-add-repository ppa:ansible/ansible $ ...

  2. 8. 利用Ansible快速构建MGR | 深入浅出MGR

    GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 目录 1. 安装ansbile 2. 配置ansible 3. 建立ssh信任 4. 测试ansible 5. 使用ans ...

  3. Win7快速启动栏

    http://jingyan.baidu.com/article/456c463bbc1d140a583144cf.html 1. 在任务栏上右键 -> 工具栏 -> 新建工具栏.   在 ...

  4. Atitit 控制中心快速启动面板quick launcher

    Atitit 控制中心快速启动面板quick launcher contralPanel.bat aaaControlPanel.contrlx /AtiPlatf_auto/src_atibrow/ ...

  5. 使用Yeoman快速启动AngularJS项目开发

    本博客停止更新,请访问新个人博客:owenchen.net 前言 博客迁移到了BAE上,http://owenchen.net/,以后的文章会首发在自己的博客上,随后在博客园发布. 很久没有写文章了, ...

  6. 神逸之作:国产快速启动软件神品ALTRun

    http://xbeta.info/altrun.htm 作者: ET民工和塞壬 日期: 2010-09-15 分类: windows 标签: quick-launch <神逸之作:国产快速启动 ...

  7. win7和win8如何设置快速启动栏

    a.在任务栏上右键 -> 工具栏 -> 新建工具栏 -> 跳出选择文件夹对话框,在文件夹里面(光标山洞处)输入这个路径,然后按回车: %userprofile%\AppData\Ro ...

  8. Linux系统快速启动方案

    =========================        基本常识       ========================= Linux系统基本启动流程: 1. CPU从ROM(如果有的 ...

  9. win7 系统如何设置快速启动栏

    a.在任务栏上右键 -> 工具栏 -> 新建工具栏 -> 跳出选择文件夹对话框,在文件夹里面(光标山洞处)输入这个路径,然后按回车: %userprofile%\AppData\Ro ...

  10. win+r 快速启动应用程序

    如何使用WIN+R快捷键快速启动应用程序呢?其实很简单 首先随便在一个盘上建一个新文件夹,随便取什么名字,最好是英文格式,小编以D盘为例,如图 2. 打开文件夹,单击右键,选择“新建”,单击“快捷方式 ...

随机推荐

  1. python对BP神经网络实现

    python对BP神经网络实现 一.概念理解 开始之前首先了解一下BP神经网络,BP的英文是back propagationd的意思,它是一种按误差反向传播(简称误差反传)训练的多层前馈网络,其算法称 ...

  2. Jenkins 系统管理与配置

    1. Jenkins 安装插件的两种方式 2. 添加凭据(Credentials) 3. 系统管理--全局工具配置 4. 系统管理--系统设置 5. 常用插件说明 Extended E-mail No ...

  3. Linux启动流程和服务管理(init和systemd)

    目录 一:Linux启动流程 init和Systemd的区别 二:Linux服务管理(service,systemctl) 一:Linux启动流程 Rhel6启动过程: Rhel7启动过程: GRUB ...

  4. hdu5247找连续数(打表)

    题意(中问题直接粘题意吧)                                 找连续数 Problem Description 小度熊拿到了一个无序的数组,对于这个数组,小度熊想知道是否 ...

  5. 快速运行cmd

    方法一 运行 windows+r 输入cmd 指定要手动输入cd ...... 方法二 文件地址栏 在指定路径在文件地址栏前面输入cmd 方法三 shift+鼠标右键 打开到指定文件夹,shift+鼠 ...

  6. 如何在spring boot中从控制器返回一个html页面?

    项目截图 解决方法 我之前用的@RestController注解,而@RestController这个控制器返回数据而不是视图,改成@Controller 就好了(以下是修改后的) @Controll ...

  7. TP之安全机制

    防止sql注入 1.查询条件尽量使用数组方式,具体如下: 1 $wheres = array(); 2 3 $wheres['account'] = $account; 4 5 $wheres['pa ...

  8. layui中的分页laypage

    1.html部分 <div id="test1"></div> 2.js部分: <script src="/static/build/lay ...

  9. 如何使用mongo shell

    Cd到MongoDb安装目录到bin目录下,执行mongo命令即可,其他命令参考手册:https://www.runoob.com/mongodb/mongodb-create-collection. ...

  10. 测开之Python自动化全栈工程师+性能专项(送思维导图)

    测开之Python自动化全栈工程师+性能专项 功能测试基础 接口测试基础接口的通信原理与本质cookie.session.token详解接口测试的意义与测试方法接口测试用例的设计 app测试 app流 ...