1. 查看 详细 信息

如果你想要查看成功模块和不成功的详细输出,使用 --verbose 标识

2. 检查 playbook 的语法

使用 ansible-playbook 的 --syntax-check 标识。通过parser来运行playbook,确保Include files、roles等没有语法错误。

3. 在运行playbook之前,查看playbook影响的哪些主机

ansible-playbook playbook.yml --list-hosts

4. 运行playbook的方式

ansible-playbook playbook.yml -f 10

5. 特权上升的方式更改为 become

6. 指定主机顺序执行playbook

inventory:
  The default. The order is ‘as provided’ by the inventory
reverse_inventory:
  As the name implies, this reverses the order ‘as provided’ by the inventory
sorted:
  Hosts are alphabetically sorted by name
reverse_sorted:
  Hosts are sorted by name in reverse alphabetical order
shuffle:
  Hosts are randomly ordered each run

7. 任务可以使用历史遗留格式: action: module options 来声明,但是推荐使用 module: options 格式

8. 大多数模块使用 “key=value” 来指定参数,例如服务模块。但是 “command and shell ” 模块使用的是参数列表,不使用“key=value”格式。

tasks:
- name: enable selinux
command: /sbin/setenforce 1 command和shell模块关心返回值,因此如果你有的命令退出码不为0,你可能希望这么做:
tasks:
- name: run this command and ignore the result
shell: /usr/bin/somecommand || /bin/true
tasks:
- name: run this command and ignore the result
shell: /usr/bin/somecommand
ignore_errors: True

9. 如果一行太长了,在下一行使用一个空格缩进表示命令的继续

tasks:
- name: Copy ansible inventory file to client
copy: src=/etc/ansible/hosts dest=/etc/ansible/hosts
owner=root group=root mode=

10. playbook 可能有四个包含任务的部分

pre_tasks, tasks, post_tasks, roles

11. handlers 需要注意的

handler执行的时机:

  • handlers notified within pre_taskstasks, and post_tasks sections are automatically flushed in the end of section where they were notified;
  • handlers notified within roles section are automatically flushed in the end of tasks section, but before any tasks handlers.  表明 roles 会跟tasks section合并

  此外,通过meta,可以提前执行handler:

tasks:
- shell: some tasks go here
- meta: flush_handlers
- shell: some other tasks

可以指定监听的主题

handlers:
- name: restart memcached
service: name=memcached state=restarted
listen: "restart web services"
- name: restart apache
service: name=apache state=restarted
listen: "restart web services" tasks:
- name: restart everything
command: echo "this task will restart the web services"
notify: "restart web services"

【Ansible 文档】提示、推荐、注意事项的更多相关文章

  1. Atitit 项目文档规范化与必备文档与推荐文档列表

    Atitit 项目文档规范化与必备文档与推荐文档列表 ===========比较重要的必备文档========== 项目组名单通讯录( 包括项目组,客户沟通人等 需求文档 原型ui文档 开发计划表 项 ...

  2. WebBrowser打开Word文档的一些注意事项

    WebBrowser打开Word文档的一些注意事项 分类: C#word2010-03-31 21:26 5640人阅读 评论(3) 收藏 举报 webbrowser文档browser工具object ...

  3. 【Ansible 文档】【译文】配置文件

    这里说明一下配置文件的内容,原文地址:http://docs.ansible.com/ansible/latest/intro_configuration.html 这个与[Ansible 文档]配置 ...

  4. 【Ansible 文档】【译文】入门教程

    http://docs.ansible.com/ansible/latest/intro_getting_started.html Foreword 前言 到这里,你应该已经安装了Ansible,是时 ...

  5. 【Ansible 文档】【译文】Ad-Hoc 命令介绍

    Introduction To Ad-Hoc Commands Ad-Hoc命令介绍 下面的例子展示了如何使用 /usr/bin/ansible 来运行ad hoc任务. 什么是ad hoc命令? 一 ...

  6. SharePoint 上传文档提示别人迁出

    前言 我们在使用SharePoint文档库的时候,经常会遇到文档被别人迁出,自己无法修改的情况.这时候,我们最好的办法就是找到那个迁出的人,怼他!如果,他已经离职了,我们无法找到,那么,就请继续往瞎看 ...

  7. 【Ansible 文档】【译文】Playbooks 变量

    Variables 变量 自动化的存在使得重复的做事情变得很容易,但是我们的系统不可能完全一样. 在某些系统中,你可能想要设置一些与其他系统不一样的行为和配置. 同样地,远程系统的行为和状态也可以影响 ...

  8. 【Ansible 文档】【译文】网络支持

    Networking Support 网络支持 Working with Networking Devices 使用网络设备 自从Ansible 2.1开始,你现在可以使用成熟模型 - 编写 play ...

  9. 【Ansible 文档】【译文】Windows 支持

    see also:List of Windows Modules Windows Support Windows 支持 Windows: How Does It Work Windows:如何工作 正 ...

  10. 【Ansible 文档】【译文】常见问题

    http://docs.ansible.com/ansible/latest/faq.html 如何为一个task或者整个Playbook设置PATH或者任意其他环境变量? 通过environment ...

随机推荐

  1. MySQL 进阶之索引

    一,索引前传 在了解数据库索引之前,首先有必要了解一下数据库索引的数据结构基础,那么什么样的数据结构可以作为索引呢? B-tree是最常用的用于索引的数据结构.因为它们是时间复杂度低, 查找.删除.插 ...

  2. 史上最详细nodejs版本管理器nvm的安装与使用(附注意事项和优化方案)

    使用场景 在Node版本快速更新迭代的今天,新老项目使用的node版本号可能已经不相同了,node版本更新越来越快,项目越做越多,node切换版本号的需求越来越迫切,传统卸载一个版本在安装另一个版本的 ...

  3. 分布式文件系统FastDFS安装教程

    前言 FastDFS(Fast Distributed File System)是一款开源轻量级分布式文件系统,本文不讲解原理和架构,只是在个人使用部署过程中耗费了好长时间和精力,遇到了很多的坑,于是 ...

  4. SpringBoot(3) 文件上传和访问

    springboot文件上传 MultipartFile file,源自SpringMVC MultipartFile 对象的transferTo方法,用于文件保存(效率和操作比原先用FileOutS ...

  5. Apollo 3 定时/长轮询拉取配置的设计

    前言 如上图所示,Apollo portal 更新配置后,进行轮询的客户端获取更新通知,然后再调用接口获取最新配置.不仅仅只有轮询,还有定时更新(默认 5 分钟一次).目的就是让客户端能够稳定的获取到 ...

  6. [转]简单的动态修改RDLC报表页边距和列宽的方法

    本文转自:http://star704983.blog.163.com/blog/static/136661264201161604413204/ 1.修改页边距 XmlDocument XMLDoc ...

  7. .Net敏捷开发框架6.1.6.2版本,联系QQ:6539471

    演示地址:www.fishcmonkey.com .NET敏捷开发框架 6.1.6.2 版本发布 新增手机流程-我的流程(可查看流程进度和表单内容) 新增手机流程-待办任务(可查看流程进度和表单内容, ...

  8. 【测试记录】EF插入查询性能

    介绍     背景什么就不提了,无外乎出现了大数据需要处理.简单的说就是我测试了EF正常的插入以及一个优化小方式而已,然后做了查询记录.其余没有什么,写这篇只是为了记录结果方便以后数据参考吧. 代码介 ...

  9. SQL Server 创建和修改数据表

    一.CREATE语句(创建) 1.创建DataBase 1.CONTAINMENT SQL Server 2012 新功能 , 默认值是OFF .(太高级 书上也没有详细介绍). 2.ON ON用于两 ...

  10. HashMap底层实现原理(JDK1.8)源码分析

    ref:https://blog.csdn.net/tuke_tuke/article/details/51588156 http://www.cnblogs.com/xiaolovewei/p/79 ...