ansible playbook

  ansible-playbook命令格式:

    ansible-playbook  [option]  filename(剧本名字)

     ansible-playbook 命令的常用选项:

      -C: 模拟运行

      --list-hosts: 列出剧本主机清单     

      --list-tags : 列出剧本标记

      --list-tasks: 列出剧本任务

      --syntax-check: 检测语法

  安装并且启动apache服务的剧本简单举例:

          

[root@host1 ansible]# mkdir ansible_playbook
[root@host1 ansible]# ll
total 24
-rw-r--r-- 1 root root 19980 Sep 14 04:00 ansible.cfg
drwxr-xr-x 2 root root 6 Oct 24 08:28 ansible_playbook
-rw-r--r-- 1 root root 40 Oct 9 15:04 hosts
drwxr-xr-x 2 root root 6 Sep 14 04:00 roles

[root@host1 ansible_playbook]# pwd
/etc/ansible/ansible_playbook
[root@host1 ansible_playbook]# ll
total 4
-rw-r--r-- 1 root root 210 Oct 24 08:48 apache.yaml

        

[root@host1 ansible_playbook]# more apache.yaml 
- hosts: test1
tasks:

- name: Install Httpd
yum name=httpd state=installed

- name: Configure Httpd.conf

- name: Start Httpd Service
service name=httpd state=started enabled=yes

      检测语法举例:        

        [root@host1 ansible_playbook]# ansible-playbook --syntax-check apache.yaml

        playbook: apache.yaml

      查看剧本主机清单:

        

        

[root@host1 ansible_playbook]# ansible-playbook --list-hosts apache.yaml

playbook: apache.yaml

play #1 (test1): test1 TAGS: []
pattern: [u'test1']
hosts (2):
192.168.132.163
192.168.132.162

      查看剧本任务:

        

[root@host1 ansible_playbook]# ansible-playbook --list-tasks apache.yaml

playbook: apache.yaml

play #1 (test1): test1 TAGS: []
tasks:
Install Httpd TAGS: []
Start Httpd Service TAGS: []

       模拟运行剧本:

          

    

[root@host1 ansible_playbook]# ansible-playbook -C apache.yaml

PLAY [test1] ************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************
ok: [192.168.132.163]
ok: [192.168.132.162]

TASK [Install Httpd] ****************************************************************************************************************
changed: [192.168.132.163]
changed: [192.168.132.162]

TASK [Start Httpd Service] **********************************************************************************************************
changed: [192.168.132.162]
changed: [192.168.132.163]

PLAY RECAP **************************************************************************************************************************
192.168.132.162 : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
192.168.132.163 : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

出现如上情况说明剧本模拟运行正常,可以去直接执行剧本了!!

    下面是批量修改httpd的配置文件后重启httpd服务的ansible 剧本(文件):

注意: playbook核心元素常用的是hosts,tasks,handlers,其他两个有兴趣可以自己去研究!

   

      

        

     

ansible自动化运维04的更多相关文章

  1. Ansible自动化运维工具及其常用模块

    Ansible自动化运维工具及其常用模块 目录 Ansible自动化运维工具及其常用模块 一.Ansible简介 1. Ansible概述 2. Ansible作用 3. Ansible的工作模块 4 ...

  2. Ansible自动化运维工具-上

    [Ansible特点] 1)Ansible与saltstack均是基于Python语言开发的 2)安装使用简单,基于不同插件和模块实现各种软件,平台,版本的管理以及支持虚拟容器多层级的部署 3)不需要 ...

  3. ansible 自动化运维

    Ansible 自动化运维 ansible安装epel #yum list all *ansible*#yum install *ansible*#yum info ansible#rpm -ql a ...

  4. Ansible 自动化运维工具

    Ansible 自动化运维工具 Ansible是什么? Ansible是一个"配置管理工具"也是一个"自动化运维工具" Ansible 作用: Ansible是 ...

  5. ansible自动化运维03

    ansible自动化运维常用模块 常用模块实现的功能:安装软件包:修改配置文件:创建程序用户组:创建目录,并修改所属和权限:挂载:启动服务:测试. command模块: shell模块: 注意:com ...

  6. 简单聊一聊Ansible自动化运维

    一.Ansible概述 Ansible是今年来越来越火的一款开源运维自动化工具,通过Ansible可以实现运维自动化,提高运维工程师的工作效率,减少人为失误.Ansible通过本身集成的非常丰富的模块 ...

  7. Ansible自动化运维工具的使用

                                 Ansible自动化运维工具的使用       host lnventory 管理主机 ip  root账号密码 ssh端口 core mod ...

  8. Ansible 自动化运维——剧本(playbook)

    Ansible 自动化运维--剧本(playbook) 1.playbook介绍: playbook是ansible用于配置,部署,和管理被控节点的剧本.通过playbook的详细描述,执行其中的ta ...

  9. 一文详解 Ansible 自动化运维

    开源Linux 一个执着于技术的公众号 一.Ansible 概述 Ansible 是近年来越来越火的一款开源运维自动化工具,通过Ansible可以实现运维自动化,提高运维工程师的工作效率,减少人为失误 ...

随机推荐

  1. JS中的箭头函数与this

    转载自:https://juejin.im/post/5aa1eb056fb9a028b77a66fd#heading-1 JavaScript在ES6语法中新增了箭头函数,相较于传统函数,箭头函数不 ...

  2. B1005 继续(3n+1)猜想 (25 分)

    一.技术总结 一个是注意输出格式,也就是末尾没有空格,这个解决方法一般是使用一个计数,然后打印输出一个就减少一个. 就是在使用数组时,要注意段错误,也就是数组开辟的是否够大. 如果可以的话,可以多设置 ...

  3. WPF DataGrid 鼠标对表格双击导致客户端崩溃

    该问题是由于在创建DataGrid时没有设置为只读属性 解决:             <DataGrid Name="switchInfoList" MouseLeftBu ...

  4. 运维工程师打怪升级进阶之路 V2.0

    在此之前,发布过两个版本: 运维工程师打怪升级之路 V1.0 版本发布 运维工程师打怪升级必经之路 V1.0.1 很多读者伙伴们反应总结的很系统.很全面,无论是0基础初学者,还是有基础的入门者,或者是 ...

  5. 慕课网springboot博客系统开发(一)----spring initializr的使用 gradle构建项目

    spring initializr工具的地址:https://start.spring.io/:通过它可以很方便的创建springboot项目 这里我们选择使用gradle作为项目的构建工具,此spr ...

  6. Intellij-Cannot download Sources解决方法

    当你点击Dowload Sources的时候它会报一个错误 提示你不能下载源代码,这个时候你可以打开下方的命令窗口 然后 进入到项目根路径后  使用mvn dependency:resolve -Dc ...

  7. 《Linux就该这么学》培训笔记_ch02_一些必须掌握的Linux命令

    本文在原来作者的基础上做一些符合自己的修改.原文参考: <Linux就该这么学>培训笔记_ch02_一些必须掌握的Linux命令.     本章的内容虽然多,基本都是书本原话,但是笔记能精 ...

  8. 解决python错误 UnicodeDecodeError: 'gb2312' codec can't decode byte 0x8b in position 1: illegal multibyte sequence

    报错的代码: url= 'http://kaijiang.500.com/shtml/ssq/19001.shtml' page =urllib.request.urlopen(url) conten ...

  9. this的用法-(2019-3)

    作为前端程序员,this应该不会陌生,指执行期的上下文,以下总结了this的几种场景: 1.全局作用域下,this指的就是Window,在控制台输出this,返回的是Window对象 2.在一般函数中 ...

  10. jQuery实现C#CheckBoxList模糊搜索

    前言 最近开发的一套系统中需要对商品进行管理,在选择商品时,要分别从品牌.型号.商品三个类别分别选择对应的选项才能找到需要的商品,三者的关系为:品牌包含型号,型号包含商品,因此使用了三个不同的 asp ...