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. springboot开发环境搭建

    姓名:陈中娇   班级:软件151 第一步:在Eclipse下面配置Maven环境: 一.使用spring boot新建maven工程不在需要建立maven web工程,只要一般的maven工程就好了 ...

  2. gitflow工作流简介

    gitflow工作流是一种依赖于Git版本管理工具,按特定规范对项目开发.测试.上线流程进行管理的工作方式.它是一种为实现规范化管理的约定,它明确了各个分支的意义,使整个团队的分工协作更加和谐明晰. ...

  3. 使用lombok 简化代码

    第一步:添加依赖 第二步:下载 lombok  jar 包 第三步 :打开cmd 命令行 执行命令, -javaagent:lombok.jar -Xbootclasspath/a:lombok.ja ...

  4. HDU2665(可持久化线段树板子)

    1.题意有坑,实际要求第k小. 2.没学过动态开点也没学过主席树,看一下博主思路然后妄想自己实现的后果就是拿命去调bug. const int maxn = 1e5 + 5; int test, n, ...

  5. git只clone仓库中指定子目录和指定文件的实现

    ## step :初始化空库 [root@vm_test backup]# mkdir devops [root@vm_test backup]# cd devops/ [root@vm_test d ...

  6. Spark2.3.0 报 io.netty.buffer.PooledByteBufAllocator.metric

    Spark2.3.0依赖的netty-all-4.1.17.Final.jar 与 hbase1.2.0依赖的netty-all-4.0.23.Final.jar 冲突 <!-- Spark2. ...

  7. vue(4)hello world

    在前一章基础上开发. 1.下载vue.js.(https://cn.vuejs.org/v2/guide/installation.html) 在hello-vue根目录下创建js文件夹,并将该vue ...

  8. 1.centos7 安装zookeeper

    1.安装jdk 1)查找jdk包: yum search java|grep jdk 2)安装: yum install -y java-1.8.0-openjdk.x86_64 2. 安装ZooKe ...

  9. sshd_config注释

    [root@H0f ~]# cat /etc/ssh/sshd_config #update by H0f -- # $OpenBSD: sshd_config,v // :: djm Exp $ # ...

  10. thinkphp模板布局

    不知道我们会不会有这样一个困惑,,每当进行一个项目时,发现页面都有好多重复的地方,假如我们每个页面都写,不仅降低的代码的运行效率 而且还不利于后期维护!TP中的模板布局就解决了这一难题! 我们就以Ad ...