Skip to content

Commit c3788da

Browse files
committed
Added 'src/usage/playbook/using/example.md'.
1 parent 5907890 commit c3788da

File tree

5 files changed

+116
-0
lines changed

5 files changed

+116
-0
lines changed

playbook_example/inventory.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
dbservers:
2+
hosts:
3+
almalinux-39:
4+
ansible_host: 192.168.122.39
5+
vars:
6+
db_port: 5432
7+
8+
webservers:
9+
hosts:
10+
almalinux-5:
11+
ansible_host: 192.168.122.5
12+
debian-199:
13+
ansible_host: 192.168.122.199
14+
vars:
15+
http_port: 443
16+
17+
lbservers:
18+
hosts:
19+
almalinux-61:
20+
ansible_host: 192.168.122.61
21+
22+
monitoring:
23+
hosts:
24+
almalinux-207:
25+
ansible_host: 192.168.122.207
26+
27+
facility:
28+
children:
29+
dbservers:
30+
lbservers:
31+
monitoring:
32+
33+
website:
34+
children:
35+
facility:
36+
webservers:
37+
vars:
38+
ansible_user: hector

playbook_example/site.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
# This playbook deploys the whole application stack in this site.
3+
4+
# Apply common configuration to all hosts
5+
- hosts: all
6+
7+
roles:
8+
- common
9+
10+
# Configure and deploy database servers.
11+
- hosts: dbservers
12+
13+
roles:
14+
- db
15+
16+
# Configure and deploy the web servers. Note that we include two roles
17+
# here, the 'base-apache' role which simply sets up Apache, and 'web'
18+
# which includes our example web application.
19+
20+
- hosts: webservers
21+
22+
roles:
23+
- base-apache
24+
- web
25+
26+
# Configure and deploy the load balancer(s).
27+
- hosts: lbservers
28+
29+
roles:
30+
- haproxy
31+
32+
# Configure and deploy the Nagios monitoring node(s).
33+
- hosts: monitoring
34+
35+
roles:
36+
- base-apache
37+
- nagios

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
- [交互式输入:提示符](usage/playbook/using/prompts.md)
7777
- [使用变量](usage/playbook/using/vars.md)
7878
- [发现变量:事实与魔法变量](usage/playbook/using/facts_and_magic_vars.md)
79+
- [Playbook 示例: 持续交付和滚动升级](usage/playbook/using/example.md)
7980
- [执行 playbook](usage/playbook/executing.md)
8081
- [标签](usage/playbook/executing/tags.md)
8182
- [高级 playbook 语法](usage/playbook/adv_syntax.md)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Playbook 示例: 持续交付和滚动升级
2+
3+
## 何谓持续交付?
4+
5+
持续交付(Continuous Delivery, CD),是指频繁地向软件应用,投送更新。
6+
7+
出发点是,通过更频繁地更新,咱们就不必等待特定时间段,而咱们的组织在应对变化过程上,也会变得更好。
8+
9+
10+
有些 Ansible 用户正每小时甚至更频繁地,有时是在每次有批准的代码变更时,就会向最终用户部署更新。为达成这点,咱们需要一些工具,以便能够以零停机时间方式,快速应用这些更新,apply those updates in a zero-downtime way。
11+
12+
13+
本文档以 Ansible 最完整的示例 playbook 之一:`lamp_haproxy` 为模板,详细介绍了如何实现这一目标。该示例使用了大量 Ansible 功能:角色、模板与组变量等,而且还附带了一个可对 web 应用程序栈,进行零停机滚动升级的编排 playbook。
14+
15+
这些 playbook 会将 Apache、PHP、MySQL、Nagios 和 HAProxy,部署到一组基于 CentOS 的服务器上。
16+
17+
我们(作者)不会在此介绍如何运行这些 playbook。请阅读 GitHub 项目中的 README,以及示例以获取相关信息。相反,我们将仔细研究该 playbook 的每一部分,并描述其做了些什么。
18+
19+
20+
## 站点部署
21+
22+
咱们从 `site.yml` 开始。这是咱们整个站点的部署 playbook。他可用于初始部署站点,以及向所有服务器推送更新:
23+
24+
25+
```yaml
26+
{{#include ../../../../playbook_example/site.yml}}
27+
```
28+
29+
> **注意**:若咱们对 playbook 及 play 等术语不熟悉,那么应该复习一下 [“使用游戏本”](../using.md)
30+
31+
在这个 playbook 中,咱们有 5 个 play。第一个以 `all` 主机为目标,并将 `common` 这个角色应用于所有主机。这是对整个站点的,比如 yum 软件包仓库配置、防火墙配置及其他需要应用到所有服务器的配置。
32+
33+
接下来的四个 play,会针对特定主机组运行,并将特定角色应用于这些服务器。除了用于 Nagios 监控、数据库和 Web 应用程序的角色外,咱们还实现了个安装和配置基本 Apache 设置的 `base-apache` 角色。该角色同时被其中的示例 web 应用及 Nagios 主机用到。
34+
35+
36+
## 可重用内容:角色

src/usage/playbook/using/templating.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Ansible 使用 Jinja2 模板,实现动态表达式及对 [变量](vars.md) 和
77

88
> **注意**[模板模组](../../collections/ansible_builtin.md) 使用的文件和数据,必须使用 utf-8 编码。
99
10+
> **译注**:在另一个广泛使用的,专为网络管理的自动化方案 [NetBox](https://github.com/netbox-community/netbox) 中,也用到了 Jinja2 模板。
11+
>
12+
> 参考:[Jinja2 Tutorial](https://ttl255.com/jinja2-tutorial-part-1-introduction-and-variable-substitution/)
13+
1014

1115
## Jinja2 示例
1216

0 commit comments

Comments
 (0)