在「Ansible 用 Roles 部署 LNMP 網(wǎng)頁(yè)應(yīng)用程式(下)」里,我們寫(xiě)好了部署 TestLink 的 Playbooks,接下來(lái)凍仁將分享上傳至 Galaxy 前的注意事項(xiàng)。
范例 lab/ch23/testlink
其實(shí)就是個(gè)把 Playbooks 拆開(kāi)的 Role,它真正的程式進(jìn)入點(diǎn)為 tasks/main.yml
,而 setup.yml
只是為了測(cè)試 Playbooks 的正確性而存在的。這也是為什么凍仁會(huì)用 setup.yml
include tasks/main.yml
,再用 tasks/main.yml
include 其它 tasks 的原因。
在「Ansible 維護(hù)大型的 Playbooks」一文時(shí),凍仁建議大家把 Playbooks 給拆開(kāi),為的就是要把它打包成 Roles。
$ tree -L 2
.
├── README.md
├── Vagrantfile
├── defaults
│ └── main.yml
├── handlers
│ └── main.yml
├── requirements.yml
├── setup.yml
├── tasks
│ ├── check.yml
│ ├── main.yml
│ ├── setting_nginx.yml
│ ├── setting_php-fpm.yml
│ ├── setting_testlink.yml
│ └── setup_testlink.yml
└── templates
├── config_db.inc.php.j2
├── nginx-testlink.conf.j2
├── php7-cli.ini.j2
└── php7-fpm.ini.j2
4 directories, 16 files
requirements.yml
, setup.yml
只有在作為 Playbooks 用時(shí)才會(huì)被使用。README.md
里提供清楚的說(shuō)明文件。meta/main.yml
) 提供正確的資訊。meta/main.yml
) 寫(xiě)入 Roles 的相依性 (Dependencies) 設(shè)定。借由 Travis CI 整合測(cè)試 Roles。(more)
就上面的例子而言,我們會(huì)用
setup.yml
來(lái)進(jìn)行測(cè)試。
ansible-galaxy init
指令建立 Role 時(shí)會(huì)一并產(chǎn)生的檔案之一。$ cat README.md
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the globalscope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
▲ 此為 ansible-galaxy init
產(chǎn)生的 READNE.md 范例。
meta/main.yml
)ansible-galaxy init
指令建立 Role 時(shí)會(huì)一并產(chǎn)生的檔案之一。$ cat meta/main.yml
galaxy_info:
author: chusiang
description: Deploy TestLink with Nginx, PHP 7 (php-fpm) and MySQL 5.6 on Ubuntu and Debian.
company: commandp Inc.
license: MIT
min_ansible_version: 2.1.2.0
platforms:
- name: Ubuntu
versions:
- trusty
- name: Debian
versions:
- jessie
galaxy_tags:
- testlink
- cms
dependencies:
- williamyeh.nginx
- chusiang.php7
- geerlingguy.mysql
▲ 此為 chusiang.testlink
role 的 meta/main.yml
。
meta/main.yml
的 dependencies
下方補(bǔ)上。$ cat meta/main.yml
...
dependencies:
- williamyeh.nginx
- chusiang.php7
- geerlingguy.mysql
▲ 此為 chusiang.testlink
role 的 meta/main.yml
。
以上就是要上傳到 Galaxy 前該特別留意的地方,下章凍仁將講解怎么把 Roles 上傳至 Galaxy。
更多建議: