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. vue.js组件之j间的通讯二

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  2. Kibana源码启动报错记录--ENOSPC

    执行该命令可解决:echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysc ...

  3. poj 1664放苹果(递归)

    放苹果 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37377   Accepted: 23016 Description ...

  4. 缓存方案:本地guavaCache, 远程redis?

    线程内部缓存:a. 局部变量HashMap, 方法间传递  b. 使用ThreadLocal 本地缓存:单jvm内共享 可以使用(Concurrent)HashMap自己实现,也可以使用GuavaCa ...

  5. linux下WordPress安装

    http://www.cnblogs.com/xiaofengkang/ WordPress简介 WordPress 是一种使用 PHP语言和 MySQL数据库开发的开源.免费的Blog(博客,网志) ...

  6. GO 日志追加记录

    以追加的方式将程序输出到不同的日志文件,当日志文件超过10M大小时,自动清空文件. package tools import ( "fmt" "log" &qu ...

  7. PHP、thinkPHP5.0开发网站文件管理功能(三)编辑文件

    public function edit(){ $file = iconv('UTF-8','GB2312',urldecode(input('file'))); if(empty($file)|| ...

  8. RTT之内存管理及异常中断

    内存管理分静态内存管理和动态内存管理(根据大小又分2种) 静态内存管理:创建.删除.初始化.解绑.申请和释放.初始化内存池是属于静态内存管理,与创建内存池不同的是,此处内存池对象所使用的内存空间是由用 ...

  9. leetcode 627. Swap Salary 数据库带判断的更新操作

    https://leetcode.com/problems/swap-salary/description/ 用  set keyWord = Case depentedWord when haha ...

  10. python单元测试框架-unittest(四)之用例综合框架管理

    简述为何如要框架? 前面测试用例与执行都是写在一个文件,当用例数量不断增加的时候,用例的执行与管理变得非常麻烦,因此需要对用例根据具体的功能模块来使用单独的模块来管理.就像一所学校要根据不同年级进行分 ...