Content Organization

production                # inventory file for production servers
stage # inventory file for stage environment group_vars/
group1 # here we assign variables to particular groups
group2 # ""
host_vars/
hostname1 # if systems need specific variables, put them here
hostname2 # "" library/ # if any custom modules, put them here (optional)
filter_plugins/ # if any custom filter plugins, put them here (optional) site.yml # master playbook
webservers.yml # playbook for webserver tier
dbservers.yml # playbook for dbserver tier roles/
common/ # this hierarchy represents a "role"
tasks/ #
main.yml # <-- tasks file can include smaller files if warranted
handlers/ #
main.yml # <-- handlers file
templates/ # <-- files for use with the template resource
ntp.conf.j2 # <------- templates end in .j2
files/ #
bar.txt # <-- files for use with the copy resource
foo.sh # <-- script files for use with the script resource
vars/ #
main.yml # <-- variables associated with this role
defaults/ #
main.yml # <-- default lower priority variables for this role
meta/ #
main.yml # <-- role dependencies webtier/ # same kind of structure as "common" was above, done for the webtier role
monitoring/ # ""
fooapp/ # ""

Use Dynamic Inventory With Clouds

Dynamic Inventory

How to Differentiate Stage vs Production

# file: production

[atlanta-webservers]
www-atl-1.example.com
www-atl-2.example.com [boston-webservers]
www-bos-1.example.com
www-bos-2.example.com [atlanta-dbservers]
db-atl-1.example.com
db-atl-2.example.com [boston-dbservers]
db-bos-1.example.com # webservers in all geos
[webservers:children]
atlanta-webservers
boston-webservers # dbservers in all geos
[dbservers:children]
atlanta-dbservers
boston-dbservers # everything in the atlanta geo
[atlanta:children]
atlanta-webservers
atlanta-dbservers # everything in the boston geo
[boston:children]
boston-webservers
boston-dbservers # 按主机、区域、数据中心划分

Group And Host Variables

---
# file: group_vars/atlanta
ntp: ntp-atlanta.example.com
backup: backup-atlanta.example.com ---
# file: group_vars/webservers
apacheMaxRequestsPerChild: 3000
apacheMaxClients: 900 ---
# file: group_vars/all
ntp: ntp-boston.example.com
backup: backup-boston.example.com ---
# file: host_vars/db-bos-1.example.com
foo_agent_port: 86
bar_agent_port: 99 # 注意主机变量&组变量的覆盖

Top Level Playbooks Are Separated By Role

---
# file: site.yml
- include: webservers.yml
- include: dbservers.yml ---
# file: webservers.yml
- hosts: webservers
roles:
- common
- webtier ansible-playbook site.yml --limit webservers
ansible-playbook webservers.yml

Task And Handler Organization For A Role

---
# file: roles/common/tasks/main.yml - name: be sure ntp is installed
yum: pkg=ntp state=installed
tags: ntp - name: be sure ntp is configured
template: src=ntp.conf.j2 dest=/etc/ntp.conf
notify:
- restart ntpd
tags: ntp - name: be sure ntpd is running and enabled
service: name=ntpd state=running enabled=yes
tags: ntp ---
# file: roles/common/handlers/main.yml
- name: restart ntpd
service: name=ntpd state=restarted

What This Organization Enables (Examples)

ansible-playbook -i production site.yml
ansible-playbook -i production site.yml --tags ntp
ansible-playbook -i production webservers.yml ansible-playbook -i production webservers.yml --limit boston
ansible-playbook -i production webservers.yml --limit boston[0-10]
ansible-playbook -i production webservers.yml --limit boston[10-20] ansible boston -i production -m ping
ansible boston -i production -m command -a '/sbin/reboot' # confirm what task names would be run if I ran this command and said "just ntp tasks"
ansible-playbook -i production webservers.yml --tags ntp --list-tasks # confirm what hostnames might be communicated with if I said "limit to boston"
ansible-playbook -i production webservers.yml --limit boston --list-hosts

Deployment vs Configuration Organization

Stage(test) vs Production

Rolling Updates

Delegation, Rolling Updates, and Local Actions.

Always Mention The State

Group By Roles

Operating System and Distribution Variance

ansible使用8-Best Practices的更多相关文章

  1. Ansible自动化运维笔记1(安装配置)

    1.Ansible的安装 pip install ansible==1.9.1 ansible1.9.1版本依赖的软件有 Python2.6以上版本 paramiko模块 PyYAML Jinja2 ...

  2. 如何利用ansible callback插件对执行结果进行解析

    最近在写一个批量巡检工具,利用ansible将脚本推到各个机器上执行,然后将执行的结果以json格式返回来. 如下所示: # ansible node2 -m script -a /root/pyth ...

  3. 《Ansible权威指南》笔记(2)——Inventory配置

    四.Inventory配置ansible通过Inventory来定义主机和组,使用时通过-i指定读取,默认/etc/ansible/hosts.可以存在多个Inventory,支持动态生成.1.定义主 ...

  4. useful Ansible commands

    This article includes some useful Ansible commands. I will try to write blogs by English. You may wa ...

  5. 《Ansible权威指南》笔记(4)——Playbook

    七.Playbook1.语法特性如下:(1)"---"首行顶格开始(2)#号注释(3)缩进统一,不同的缩进代表不同的级别,缩进要对齐,空格和tab不能混用(4)区别大小写,键值对k ...

  6. 《Ansible权威指南》笔记(3)——Ad-Hoc命令集,常用模块

    五.Ad-Hoc命令集1.Ad-Hoc命令集通过/usr/bin/ansible命令实现:ansible <host-pattern> [options]    -v,--verbose  ...

  7. 《Ansible权威指南》笔记(1)——安装,ssh密钥登陆,命令

    2016-12-23 读这本<Ansible权威指南>学习ansible,根据本书内容和网上的各种文档,以及经过自己测试,写出以下笔记.另,这本书内容很好,但印刷错误比较多,作者说第二版会 ...

  8. 自动化运维工具ansible部署以及使用

    测试环境master 192.168.16.74webserver1 192.168.16.70webserver2 192.168.16.72安装ansiblerpm -Uvh http://ftp ...

  9. Ansible Ubuntu 安装部署

    一.安装: $ sudo apt-get install ansible 二.配置: a.基本配置 $ cd /etc/ansible/ $ sudo cp hosts hosts_back 备份一个 ...

随机推荐

  1. Centos7安装MySQL8.0

    请到这个地址看:https://www.cnblogs.com/kevingrace/p/10482469.html Centos7安装MySQL8.0 - 操作手册 一.yum安装方式: 卸载之前版 ...

  2. 001 开发环境搭建、安卓项目结构、R文件位置、asset目录创建

    1.安卓开发平台搭建 (1)下载SDK基础工具包(自己的百度云中) (2)将下载的安装包(android-sdk_r24.4.1-windows.zip)解压后,放到以下路径 C:\SoftAppli ...

  3. C语言编程思想

    模块化的思想 模块化程序的特点:单入口.单出口 基本的三种结构:顺序.分支(选择).循环: 这三个基本结构来安排模块执行的步骤: 循环三要素:初值.条件.更新: 面对编程问题:三步走策略(输入+处理+ ...

  4. Ubuntu 安装 phpredis扩展

    官网 https://github.com/phpredis/phpredis 下载->然后解压->上传服务器 /etc/phpredis 进行 cd /etc/phpredisphpiz ...

  5. 匿名类与lambda区别

    第一种是继承Thread, 重写了Thread.run()    getClass()返回的是匿名类 java.long.Thread$1 第二种是lambda, 重写了Runnable.run()  ...

  6. js apply和call

    apply()和call()这两个方法的作用是一样的,都是在特定作用域中调用函数,等于设置函数体内this对象的只,以扩充函数赖以运行的作用域 apply:方法能劫持另外一个对象的方法,继承另外一个对 ...

  7. idea各种快捷键

    工作的的时候,如果不知道idea一些方便的快捷键会大大影响工作效率,今天打算看看这些小技巧: https://blog.csdn.net/linsongbin1/article/details/802 ...

  8. ORACLE 12.2 RAC TNS-12520 遭遇连接风爆 (connection storm)

    故障现象:数据库迁移到新环境刚过两天.今天生产核心数,断断继续的告警连接不上.这是问题! 如理思路:1.查看alert日志,日志无报错                  2.查看连接数,参数设置的20 ...

  9. requirej入门(一)

    随着网站功能逐渐丰富,网页中的js也变得越来越复杂和臃肿,原有通过script标签来导入一个个的js文件这种方式已经不能满足现在互联网开发模式,我们需要团队协作.模块复用.单元测试等等一系列复杂的需求 ...

  10. E. Three strings 广义后缀自动机

    http://codeforces.com/problemset/problem/452/E 多个主串的模型. 建立一个广义后缀自动机,可以dp出每个状态的endpos集合大小.同时也维护一个R[]表 ...