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. ElementPlusViteStarterPnpm版本

    1 起因 由于最近Vite升级了2.x版本,项目中需要改动的东西有点多,本来想基于官方给出的starter重做,但是又看到了一个叫pnpm的仓库,构建速度会比原生npm/yarn快两倍以上: 因此模仿 ...

  2. Spring Boot demo系列(四):Spring Web+Validation

    2021.2.24 更新 1 概述 本文主要讲述了如何使用Hibernate Validator以及@Valid/@Validate注解. 2 校验 对于一个普通的Spring Boot应用,经常可以 ...

  3. Spring Boot demo系列(三):Spring Web+MyBatis Plus

    2021.2.24 更新 1 概述 Spring Web+MyBatis Plus的一个Demo,内容和上一篇类似,因此重点放在MyBatis Plus这里. 2 dao层 MyBatis Plus相 ...

  4. day13.常用模块

    一.time与datetime模块 1.1time 在Python中,通常有这几种方式来表示时间: 时间戳(timestamp):通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计 ...

  5. Tree Recovery UVA - 536

    Little Valentine liked playing with binary trees very much. Her favorite game was constructing rando ...

  6. Day13_67_interrupt() 方法

    interrupt() 方法 中断线程 * interrupt()方法的简单理解 - interrupt() 方法只是改变线程的阻塞状态而已,让一个正在阻塞状态的线程,恢复执行.但是它不会中断一个正在 ...

  7. kubeadm安装kubernetes1.18.5

    前言 尝试安装helm3,kubernetes1.18,istio1.6是否支持现有集群平滑迁移 版本 Centos7.6 升级内核4.x kubernetes:v1.18.5 helm:v3.2.4 ...

  8. 【C++】从零开始,只使用FFmpeg,Win32 API,实现一个播放器(一)

    前言 起初只是想做一个直接读取视频文件然后播放字符动画的程序.我的设想很简单,只要有现成的库,帮我把视频文件解析成一帧一帧的原始画面信息,那么我只需要读取里面的每一个像素的RGB数值,计算出亮度,然后 ...

  9. windows内核编程基础知识

    /* 1.基本的驱动数据结构 //驱动对象结构体 typedef struct _DRIVER_OBJECT { CSHORT Type; //结构类型 CSHORT Size; //结构大小 PDE ...

  10. Java中的反射机制Reflection

    目录 什么是反射? 获取.class字节码文件对象 获取该.class字节码文件对象的详细信息 通过反射机制执行函数 反射链 反射机制是java的一个非常重要的机制,一些著名的应用框架都使用了此机制, ...