Edit
Ansible Playbook Roles 和 Include 声明
1. Introduction
工作中我们有可能会写一个很长的playbook,最后发现playbook中很多功能是可以复用。
客观来讲,include
允许我们把playbook写成很多小文件,然后通过一定的策略include组织在一起,提高利用性。task
可以使用include
, handlers
同样也属于task
,所以handlers
也可以使用include
playbook同样也可以被include
.当你有这方面的考虑时,你已经不再止步于普通应用者,如何更好的使和组织架构是你更高的追求。这期间我们要有封装
的思想,所谓的封装
,你可以简单的理解为”我们会开汽车但必需要发动机如何工作“
roles
的概念在Ansible中比较抽象,不太形象有比喻可以理解为 class
类。roles
具备include
的功能,将比较长的playbook功能分拆通过include的将增加代码复用性。roles
站在更高一层看问题,其基于 include
, playbook
之上把整合的更为干净,复用性更高。
我们首先要理解 roles, 因为 roles 功能是如此强大,以至于我们在用到playbook功能后,一定会使用到roles功能。
2. Task Include Files And Encouraging Reuse
include
可以上我们有效提高代码复用性,请参考如下案例。
tasks/foo.yml
---
# possibly saved as tasks/foo.yml
- name: placeholder foo
command: /bin/foo
- name: placeholder bar
command: /bin/bar
如果我们希望在task中引用,如下方式可实现:
tasks:
- include: tasks/foo.yml
Include支持变量引用,我们称之为parameterized include
。举个例子,如果分发多个 wordpress 实例,我可以将 wordpress 任务排版到一个 wordprss.yml 文件,通过变量传参实现。
tasks:
- include: wordpress.yml wp_user=timmy
- include: wordpress.yml wp_user=alice
- include: wordpress.yml wp_user=bob
从1.0版本开始,ansible 同样也支持如下格式的传参:
tasks:
- include: wordpress.yml
vars:
wp_user: timmy
ssh_keys:
- keys/one.txt
- keys/two.txt
变量的引用方式如下:
{{ wp_user }}
如前面所介绍includes
同时适用于 handlers
。比如,我们定义了如何重启 apache, 但希望所有 playbook 执行前只执行一次,那么我们可以使用如下的方式进行,定义 handlers.yml:
---
# this might be in a file like handlers/handlers.yml
- name: restart apache
service: name=apache state=restarted
然后在playbook中引用
handlers:
- include: handlers/handlers.yml
include 也支持从一个playbook 导入到另外一个 playbook,同时支持层级定义。如下例:
- name: this is a play at the top level of a file
hosts: all
remote_user: root
tasks:
- name: say hi
tags: foo
shell: echo "hi..."
- include: load_balancers.yml
- include: webservers.yml
- include: dbservers.yml
这里需要留意的是,include时变量不随之生效
3. Roles
组织playbook的最好办法是什么? 使用 roles!。 roles 可以有效的把 vars_files, tasks, handlers组织起来,按角色分组可以非常容易的和其它用户分享。rles 只是自动化 include
如上的这些指令,其本身并没有魔法效果,不管如此,这是一项大工程。因为我们要合理的规划其目录结构。
site.yml
webservers.yml
fooservers.yml
roles/
common/
files/
templates/
tasks/
handlers/
vars/
defaults/
meta/
webservers/
files/
templates/
tasks/
handlers/
vars/
defaults/
meta/
写到playbook中,它长成这个样子:
---
- hosts: webservers
roles:
- common
- webservers
其中每项均有其功能介绍:
-
roles/x/tasks/main.yml
主函数,包括在其中的所有任务将被执行
-
roles/x/handlers/main.yml
所有包括中其中的 handlers 将被执行
-
roles/x/vars/main.yml
所有包括在其中的变量将在roles中生效
-
roles/x/meta/main.yml
roles所有依赖将被正常登入
-
roles/x/{files,templates,tasks}/ (dir depends on task)
所有文件,模板都将可存放在这里,放在这里最大的好处是不用指定绝对路径
---
- hosts: webservers
roles:
- common
- { role: foo_app_instance, dir: '/opt/a', app_port: 5000 }
- { role: foo_app_instance, dir: '/opt/b', app_port: 5001 }
也可以加入一定的条件:
---
- hosts: webservers
roles:
- { role: some_role, when: "ansible_os_family == 'RedHat'" }
同时,我们有可能希望为我们的角色分配 tags, tags的功能是我使用 ansible 下来体验最为深刻的功能,没有之一,实在是太灵活方便了。在考虑组织严密的同时,又不忘其灵活性。
---
- hosts: webservers
roles:
- { role: foo, tags: ["bar", "baz"] }
虽说tags 是好东西,但如果你发现你制订的roles
中具有很多tags而且经常性的会被使用,则要考虑下再次切分roles为多个roles.
同时,在一个playbook中我们可以定义多层级的任务。如下案例:
---
- hosts: webservers
pre_tasks:
- shell: echo 'hello'
roles:
- { role: some_role }
tasks:
- shell: echo 'still busy'
post_tasks:
- shell: echo 'goodbye'
4. Role Default Variables
defaults/main.yml
定义最低优化级的 roles 变量,我们可以通过很多其它方式定义的变量,均会覆盖这里的变量值
5. Role Dependencies
meta/mainl.yml
默认定义role的依赖,
---
dependencies:
- { role: common, some_parameter: 3 }
- { role: apache, appache_port: 80 }
- { role: postgres, dbname: blarg, other_parameter: 12 }
Role 依赖也可以是全路径,如:
---
dependencies:
- { role: '/path/to/common/roles/foo', x: 1 }
Roles dependencies 总是在roles最开始的时候执行,而且默认只执行一次,即使其它其它roles重复引用。
通过设置 meta/main.yml 中 allow_duplicates: yes 可以多次执行。如下例:
---
dependencies:
- { role: wheel, n: 1 }
- { role: wheel, n: 2 }
- { role: wheel, n: 3 }
- { role: wheel, n: 4 }
---
allow_duplicates: yes
dependencies:
- { role: tire }
- { role: brake }
6. Embedding Modules In Roles
这个高级话题和大部分用户无关,这里暂不做介绍
7. Ansible Galaxy
@%28%u6280%u672F%u6587%u6863%u5B66%u4E60%29%5B%u6280%u672F%7Cansible%5D%0A%0A%0AAnsible%20Playbook%20Roles%20%u548C%20Include%20%u58F0%u660E%0A%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0A%0A%5BTOC%5D%0A%0A%0A%23%23%201.%20Introduction%0A%u5DE5%u4F5C%u4E2D%u6211%u4EEC%u6709%u53EF%u80FD%u4F1A%u5199%u4E00%u4E2A%u5F88%u957F%u7684playbook%uFF0C%u6700%u540E%u53D1%u73B0playbook%u4E2D%u5F88%u591A%u529F%u80FD%u662F%u53EF%u4EE5%u590D%u7528%u3002%0A%0A%u5BA2%u89C2%u6765%u8BB2%uFF0C%60include%60%u5141%u8BB8%u6211%u4EEC%u628Aplaybook%u5199%u6210%u5F88%u591A%u5C0F%u6587%u4EF6%uFF0C%u7136%u540E%u901A%u8FC7%u4E00%u5B9A%u7684%u7B56%u7565include%u7EC4%u7EC7%u5728%u4E00%u8D77%uFF0C%u63D0%u9AD8%u5229%u7528%u6027%u3002%60task%60%u53EF%u4EE5%u4F7F%u7528%60include%60%2C%20%60handlers%60%u540C%u6837%u4E5F%u5C5E%u4E8E%60task%60%uFF0C%u6240%u4EE5%60handlers%60%u4E5F%u53EF%u4EE5%u4F7F%u7528%60include%60%0A%0Aplaybook%u540C%u6837%u4E5F%u53EF%u4EE5%u88AB%60include%60.%u5F53%u4F60%u6709%u8FD9%u65B9%u9762%u7684%u8003%u8651%u65F6%uFF0C%u4F60%u5DF2%u7ECF%u4E0D%u518D%u6B62%u6B65%u4E8E%u666E%u901A%u5E94%u7528%u8005%uFF0C%u5982%u4F55%u66F4%u597D%u7684%u4F7F%u548C%u7EC4%u7EC7%u67B6%u6784%u662F%u4F60%u66F4%u9AD8%u7684%u8FFD%u6C42%u3002%u8FD9%u671F%u95F4%u6211%u4EEC%u8981%u6709%60%u5C01%u88C5%60%u7684%u601D%u60F3%uFF0C%u6240%u8C13%u7684%60%u5C01%u88C5%60%uFF0C%u4F60%u53EF%u4EE5%u7B80%u5355%u7684%u7406%u89E3%u4E3A%u201D%u6211%u4EEC%u4F1A%u5F00%u6C7D%u8F66%u4F46%u5FC5%u9700%u8981%u53D1%u52A8%u673A%u5982%u4F55%u5DE5%u4F5C%u201C%0A%0A%60roles%60%u7684%u6982%u5FF5%u5728Ansible%u4E2D%u6BD4%u8F83%u62BD%u8C61%uFF0C%u4E0D%u592A%u5F62%u8C61%u6709%u6BD4%u55BB%u53EF%u4EE5%u7406%u89E3%u4E3A%20%60class%60%20%u7C7B%u3002%60roles%60%u5177%u5907%60include%60%u7684%u529F%u80FD%uFF0C%u5C06%u6BD4%u8F83%u957F%u7684playbook%u529F%u80FD%u5206%u62C6%u901A%u8FC7include%u7684%u5C06%u589E%u52A0%u4EE3%u7801%u590D%u7528%u6027%u3002%60roles%60%u7AD9%u5728%u66F4%u9AD8%u4E00%u5C42%u770B%u95EE%u9898%uFF0C%u5176%u57FA%u4E8E%20%60include%60%2C%20%60playbook%60%u4E4B%u4E0A%u628A%u6574%u5408%u7684%u66F4%u4E3A%u5E72%u51C0%uFF0C%u590D%u7528%u6027%u66F4%u9AD8%u3002%0A%0A%u6211%u4EEC%u9996%u5148%u8981%u7406%u89E3%20roles%2C%20%u56E0%u4E3A%20roles%20%u529F%u80FD%u662F%u5982%u6B64%u5F3A%u5927%uFF0C%u4EE5%u81F3%u4E8E%u6211%u4EEC%u5728%u7528%u5230playbook%u529F%u80FD%u540E%uFF0C%u4E00%u5B9A%u4F1A%u4F7F%u7528%u5230roles%u529F%u80FD%u3002%0A%0A%23%23%202.%20Task%20Include%20Files%20And%20Encouraging%20Reuse%0A%0A%60include%60%u53EF%u4EE5%u4E0A%u6211%u4EEC%u6709%u6548%u63D0%u9AD8%u4EE3%u7801%u590D%u7528%u6027%uFF0C%u8BF7%u53C2%u8003%u5982%u4E0B%u6848%u4F8B%u3002%0A%0Atasks/foo.yml%0A%0A%60%60%60%0A—%0A%23%20possibly%20saved%20as%20tasks/foo.yml%0A%0A-%20name%3A%20placeholder%20foo%0A%20%20command%3A%20/bin/foo%0A%0A-%20name%3A%20placeholder%20bar%0A%20%20command%3A%20/bin/bar%0A%60%60%60%0A%0A%u5982%u679C%u6211%u4EEC%u5E0C%u671B%u5728task%u4E2D%u5F15%u7528%uFF0C%u5982%u4E0B%u65B9%u5F0F%u53EF%u5B9E%u73B0%uFF1A%0A%0A%60%60%60%0Atasks%3A%0A%0A%20%20-%20include%3A%20tasks/foo.yml%0A%60%60%60%0A%0A**Include%u652F%u6301%u53D8%u91CF%u5F15%u7528%uFF0C%u6211%u4EEC%u79F0%u4E4B%u4E3A%60parameterized%20include%60**%u3002%u4E3E%u4E2A%u4F8B%u5B50%uFF0C%u5982%u679C%u5206%u53D1%u591A%u4E2A%20wordpress%20%u5B9E%u4F8B%uFF0C%u6211%u53EF%u4EE5%u5C06%20wordpress%20%u4EFB%u52A1%u6392%u7248%u5230%u4E00%u4E2A%20wordprss.yml%20%u6587%u4EF6%uFF0C%u901A%u8FC7%u53D8%u91CF%u4F20%u53C2%u5B9E%u73B0%u3002%0A%0A%60%60%60%0Atasks%3A%0A%20%20-%20include%3A%20wordpress.yml%20wp_user%3Dtimmy%0A%20%20-%20include%3A%20wordpress.yml%20wp_user%3Dalice%0A%20%20-%20include%3A%20wordpress.yml%20wp_user%3Dbob%0A%60%60%60%0A%0A%u4ECE1.0%u7248%u672C%u5F00%u59CB%uFF0Cansible%20%u540C%u6837%u4E5F%u652F%u6301%u5982%u4E0B%u683C%u5F0F%u7684%u4F20%u53C2%uFF1A%0A%0A%60%60%60%0Atasks%3A%0A%0A%20%20-%20include%3A%20wordpress.yml%0A%20%20%20%20vars%3A%0A%20%20%20%20%20%20%20%20wp_user%3A%20timmy%0A%20%20%20%20%20%20%20%20ssh_keys%3A%0A%20%20%20%20%20%20%20%20%20%20-%20keys/one.txt%0A%20%20%20%20%20%20%20%20%20%20-%20keys/two.txt%0A%60%60%60%0A%0A%u53D8%u91CF%u7684%u5F15%u7528%u65B9%u5F0F%u5982%u4E0B%uFF1A%0A%0A%20%20%20%20%7B%7B%20wp_user%20%7D%7D%0A%0A%0A%u5982%u524D%u9762%u6240%u4ECB%u7ECD%60includes%60%u540C%u65F6%u9002%u7528%u4E8E%20%60handlers%60%u3002%u6BD4%u5982%uFF0C%u6211%u4EEC%u5B9A%u4E49%u4E86%u5982%u4F55%u91CD%u542F%20apache%2C%20%u4F46%u5E0C%u671B%u6240%u6709%20playbook%20%u6267%u884C%u524D%u53EA%u6267%u884C%u4E00%u6B21%uFF0C%u90A3%u4E48%u6211%u4EEC%u53EF%u4EE5%u4F7F%u7528%u5982%u4E0B%u7684%u65B9%u5F0F%u8FDB%u884C%uFF0C%u5B9A%u4E49%20handlers.yml%3A%0A%0A%60%60%60%0A—%0A%23%20this%20might%20be%20in%20a%20file%20like%20handlers/handlers.yml%0A-%20name%3A%20restart%20apache%0A%20%20service%3A%20name%3Dapache%20state%3Drestarted%0A%60%60%60%0A%0A%u7136%u540E%u5728playbook%u4E2D%u5F15%u7528%20%0A%0A%60%60%60%0Ahandlers%3A%0A%20%20-%20include%3A%20handlers/handlers.yml%0A%60%60%60%0A%0Ainclude%20%u4E5F%u652F%u6301%u4ECE%u4E00%u4E2Aplaybook%20%u5BFC%u5165%u5230%u53E6%u5916%u4E00%u4E2A%20playbook%2C%u540C%u65F6%u652F%u6301%u5C42%u7EA7%u5B9A%u4E49%u3002%u5982%u4E0B%u4F8B%uFF1A%0A%0A%60%60%60%0A-%20name%3A%20this%20is%20a%20play%20at%20the%20top%20level%20of%20a%20file%0A%20%20hosts%3A%20all%0A%20%20remote_user%3A%20root%0A%0A%20%20tasks%3A%0A%0A%20%20-%20name%3A%20say%20hi%0A%20%20%20%20tags%3A%20foo%0A%20%20%20%20shell%3A%20echo%20%22hi…%22%0A%0A-%20include%3A%20load_balancers.yml%0A-%20include%3A%20webservers.yml%0A-%20include%3A%20dbservers.yml%0A%60%60%60%0A%0A%u8FD9%u91CC%u9700%u8981%u7559%u610F%u7684%u662F%uFF0Cinclude%u65F6%u53D8%u91CF%u4E0D%u968F%u4E4B%u751F%u6548%0A%0A%23%23%203.%20Roles%0A%0A%u7EC4%u7EC7playbook%u7684%u6700%u597D%u529E%u6CD5%u662F%u4EC0%u4E48%uFF1F%20%u4F7F%u7528%20roles%21%u3002%20roles%20%u53EF%u4EE5%u6709%u6548%u7684%u628A%20vars_files%2C%20tasks%2C%20handlers%u7EC4%u7EC7%u8D77%u6765%uFF0C%u6309%u89D2%u8272%u5206%u7EC4%u53EF%u4EE5%u975E%u5E38%u5BB9%u6613%u7684%u548C%u5176%u5B83%u7528%u6237%u5206%u4EAB%u3002rles%20%u53EA%u662F%u81EA%u52A8%u5316%20%60include%60%20%u5982%u4E0A%u7684%u8FD9%u4E9B%u6307%u4EE4%uFF0C%u5176%u672C%u8EAB%u5E76%u6CA1%u6709%u9B54%u6CD5%u6548%u679C%uFF0C%u4E0D%u7BA1%u5982%u6B64%uFF0C%u8FD9%u662F%u4E00%u9879%u5927%u5DE5%u7A0B%u3002%u56E0%u4E3A%u6211%u4EEC%u8981%u5408%u7406%u7684%u89C4%u5212%u5176%u76EE%u5F55%u7ED3%u6784%u3002%0A%0A%60%60%60%0Asite.yml%0Awebservers.yml%0Afooservers.yml%0Aroles/%0A%20%20%20common/%0A%20%20%20%20%20files/%0A%20%20%20%20%20templates/%0A%20%20%20%20%20tasks/%0A%20%20%20%20%20handlers/%0A%20%20%20%20%20vars/%0A%20%20%20%20%20defaults/%0A%20%20%20%20%20meta/%0A%20%20%20webservers/%0A%20%20%20%20%20files/%0A%20%20%20%20%20templates/%0A%20%20%20%20%20tasks/%0A%20%20%20%20%20handlers/%0A%20%20%20%20%20vars/%0A%20%20%20%20%20defaults/%0A%20%20%20%20%20meta/%0A%60%60%60%0A%0A%u5199%u5230playbook%u4E2D%uFF0C%u5B83%u957F%u6210%u8FD9%u4E2A%u6837%u5B50%uFF1A%0A%0A%60%60%60%0A—%0A-%20hosts%3A%20webservers%0A%20%20roles%3A%0A%20%20%20%20%20-%20common%0A%20%20%20%20%20-%20webservers%0A%60%60%60%0A%0A%u5176%u4E2D%u6BCF%u9879%u5747%u6709%u5176%u529F%u80FD%u4ECB%u7ECD%uFF1A%0A%0A*%20roles/x/tasks/main.yml%0A%u4E3B%u51FD%u6570%uFF0C%u5305%u62EC%u5728%u5176%u4E2D%u7684%u6240%u6709%u4EFB%u52A1%u5C06%u88AB%u6267%u884C%0A*%20roles/x/handlers/main.yml%0A%u6240%u6709%u5305%u62EC%u4E2D%u5176%u4E2D%u7684%20handlers%20%u5C06%u88AB%u6267%u884C%0A*%20roles/x/vars/main.yml%20%0A%u6240%u6709%u5305%u62EC%u5728%u5176%u4E2D%u7684%u53D8%u91CF%u5C06%u5728roles%u4E2D%u751F%u6548%0A*%20roles/x/meta/main.yml%20%0Aroles%u6240%u6709%u4F9D%u8D56%u5C06%u88AB%u6B63%u5E38%u767B%u5165%0A*%20roles/x/%7Bfiles%2Ctemplates%2Ctasks%7D/%20%28dir%20depends%20on%20task%29%20%0A%u6240%u6709%u6587%u4EF6%uFF0C%u6A21%u677F%u90FD%u5C06%u53EF%u5B58%u653E%u5728%u8FD9%u91CC%uFF0C%u653E%u5728%u8FD9%u91CC%u6700%u5927%u7684%u597D%u5904%u662F%u4E0D%u7528%u6307%u5B9A%u7EDD%u5BF9%u8DEF%u5F84%0A%0A%60%60%60%0A—%0A%0A-%20hosts%3A%20webservers%0A%20%20roles%3A%0A%20%20%20%20-%20common%0A%20%20%20%20-%20%7B%20role%3A%20foo_app_instance%2C%20dir%3A%20%27/opt/a%27%2C%20%20app_port%3A%205000%20%7D%0A%20%20%20%20-%20%7B%20role%3A%20foo_app_instance%2C%20dir%3A%20%27/opt/b%27%2C%20%20app_port%3A%205001%20%7D%0A%60%60%60%0A%0A%u4E5F%u53EF%u4EE5%u52A0%u5165%u4E00%u5B9A%u7684%u6761%u4EF6%uFF1A%0A%0A%60%60%60%0A—%0A%0A-%20hosts%3A%20webservers%0A%20%20roles%3A%0A%20%20%20%20-%20%7B%20role%3A%20some_role%2C%20when%3A%20%22ansible_os_family%20%3D%3D%20%27RedHat%27%22%20%7D%0A%60%60%60%0A%0A%u540C%u65F6%uFF0C%u6211%u4EEC%u6709%u53EF%u80FD%u5E0C%u671B%u4E3A%u6211%u4EEC%u7684%u89D2%u8272%u5206%u914D%20%20tags%2C%20tags%u7684%u529F%u80FD%u662F%u6211%u4F7F%u7528%20ansible%20%u4E0B%u6765%u4F53%u9A8C%u6700%u4E3A%u6DF1%u523B%u7684%u529F%u80FD%uFF0C%u6CA1%u6709%u4E4B%u4E00%uFF0C%u5B9E%u5728%u662F%u592A%u7075%u6D3B%u65B9%u4FBF%u4E86%u3002%u5728%u8003%u8651%u7EC4%u7EC7%u4E25%u5BC6%u7684%u540C%u65F6%uFF0C%u53C8%u4E0D%u5FD8%u5176%u7075%u6D3B%u6027%u3002%0A%0A%60%60%60%0A—%0A%0A-%20hosts%3A%20webservers%0A%20%20roles%3A%0A%20%20%20%20-%20%7B%20role%3A%20foo%2C%20tags%3A%20%5B%22bar%22%2C%20%22baz%22%5D%20%7D%0A%60%60%60%0A%0A%u867D%u8BF4tags%20%u662F%u597D%u4E1C%u897F%uFF0C%u4F46%u5982%u679C%u4F60%u53D1%u73B0%u4F60%u5236%u8BA2%u7684%60roles%60%u4E2D%u5177%u6709%u5F88%u591Atags%u800C%u4E14%u7ECF%u5E38%u6027%u7684%u4F1A%u88AB%u4F7F%u7528%uFF0C%u5219%u8981%u8003%u8651%u4E0B%u518D%u6B21%u5207%u5206roles%u4E3A%u591A%u4E2Aroles.%0A%0A%u540C%u65F6%uFF0C%u5728%u4E00%u4E2Aplaybook%u4E2D%u6211%u4EEC%u53EF%u4EE5%u5B9A%u4E49%u591A%u5C42%u7EA7%u7684%u4EFB%u52A1%u3002%u5982%u4E0B%u6848%u4F8B%uFF1A%0A%0A%60%60%60%0A—%0A%0A-%20hosts%3A%20webservers%0A%0A%20%20pre_tasks%3A%0A%20%20%20%20-%20shell%3A%20echo%20%27hello%27%0A%0A%20%20roles%3A%0A%20%20%20%20-%20%7B%20role%3A%20some_role%20%7D%0A%0A%20%20tasks%3A%0A%20%20%20%20-%20shell%3A%20echo%20%27still%20busy%27%0A%0A%20%20post_tasks%3A%0A%20%20%20%20-%20shell%3A%20echo%20%27goodbye%27%0A%60%60%60%0A%0A%23%23%204.%20Role%20Default%20Variables%0A%0A%60defaults/main.yml%60%20%u5B9A%u4E49%u6700%u4F4E%u4F18%u5316%u7EA7%u7684%20roles%20%u53D8%u91CF%uFF0C%u6211%u4EEC%u53EF%u4EE5%u901A%u8FC7%u5F88%u591A%u5176%u5B83%u65B9%u5F0F%u5B9A%u4E49%u7684%u53D8%u91CF%uFF0C%u5747%u4F1A%u8986%u76D6%u8FD9%u91CC%u7684%u53D8%u91CF%u503C%0A%0A%23%23%205.%20Role%20Dependencies%0A%0A%60meta/mainl.yml%60%u9ED8%u8BA4%u5B9A%u4E49role%u7684%u4F9D%u8D56%uFF0C%0A%0A%60%60%60%0A—%0Adependencies%3A%0A%20%20-%20%7B%20role%3A%20common%2C%20some_parameter%3A%203%20%7D%0A%20%20-%20%7B%20role%3A%20apache%2C%20appache_port%3A%2080%20%7D%0A%20%20-%20%7B%20role%3A%20postgres%2C%20dbname%3A%20blarg%2C%20other_parameter%3A%2012%20%7D%0A%60%60%60%0A%0ARole%20%u4F9D%u8D56%u4E5F%u53EF%u4EE5%u662F%u5168%u8DEF%u5F84%uFF0C%u5982%uFF1A%0A%0A%60%60%60%0A—%0Adependencies%3A%0A%20%20%20-%20%7B%20role%3A%20%27/path/to/common/roles/foo%27%2C%20x%3A%201%20%7D%0A%60%60%60%0A%0ARoles%20dependencies%20%u603B%u662F%u5728roles%u6700%u5F00%u59CB%u7684%u65F6%u5019%u6267%u884C%uFF0C%u800C%u4E14%u9ED8%u8BA4%u53EA%u6267%u884C%u4E00%u6B21%uFF0C%u5373%u4F7F%u5176%u5B83%u5176%u5B83roles%u91CD%u590D%u5F15%u7528%u3002%0A%u901A%u8FC7%u8BBE%u7F6E%20meta/main.yml%20%u4E2D%20allow_duplicates%3A%20yes%20%u53EF%u4EE5%u591A%u6B21%u6267%u884C%u3002%u5982%u4E0B%u4F8B%uFF1A%0A%0A%60%60%60%0A—%0Adependencies%3A%0A-%20%7B%20role%3A%20wheel%2C%20n%3A%201%20%7D%0A-%20%7B%20role%3A%20wheel%2C%20n%3A%202%20%7D%0A-%20%7B%20role%3A%20wheel%2C%20n%3A%203%20%7D%0A-%20%7B%20role%3A%20wheel%2C%20n%3A%204%20%7D%0A%60%60%60%0A%0A%60%60%60%0A—%0Aallow_duplicates%3A%20yes%0Adependencies%3A%0A-%20%7B%20role%3A%20tire%20%7D%0A-%20%7B%20role%3A%20brake%20%7D%0A%60%60%60%0A%0A%23%23%206.%20Embedding%20Modules%20In%20Roles%0A%0A%u8FD9%u4E2A%u9AD8%u7EA7%u8BDD%u9898%u548C%u5927%u90E8%u5206%u7528%u6237%u65E0%u5173%uFF0C%u8FD9%u91CC%u6682%u4E0D%u505A%u4ECB%u7ECD%0A%23%23%207.%20Ansible%20Galaxy%0A%0A
原创文章,作者:stanley,如若转载,请注明出处:http://www.178linux.com/13710