99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

Ansible 在 Ansible Galaxy 分享 Roles(上)

2018-07-25 11:05 更新

在「Ansible 用 Roles 部署 LNMP 網(wǎng)頁應(yīng)用程式(下)」里,我們寫好了部署 TestLink 的 Playbooks,接下來凍仁將分享上傳至 Galaxy 前的注意事項。

automate_with_ansible_practice-28.jpg

怎么把 Playbooks 打包成 Roles?

范例 lab/ch23/testlink 其實就是個把 Playbooks 拆開的 Role,它真正的程式進(jìn)入點(diǎn)為 tasks/main.yml,而 setup.yml 只是為了測試 Playbooks 的正確性而存在的。這也是為什么凍仁會用 setup.yml include tasks/main.yml,再用 tasks/main.yml include 其它 tasks 的原因。

在「Ansible 維護(hù)大型的 Playbooks」一文時,凍仁建議大家把 Playbooks 給拆開,為的就是要把它打包成 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.ymlsetup.yml 只有在作為 Playbooks 用時才會被使用。

好的 Roles 應(yīng)具備什么?

  1. 在 README.md 里提供清楚的說明文件。
  2. 在 Meta Data (meta/main.yml) 提供正確的資訊。
  3. 在 Meta Data (meta/main.yml) 寫入 Roles 的相依性 (Dependencies) 設(shè)定。
  4. 命名變數(shù)時,使用 Role 的名稱作為變數(shù)的前綴。
  5. 借由 Travis CI 整合測試 Roles。(more)

    就上面的例子而言,我們會用 setup.yml 來進(jìn)行測試。

README.md

  1. 使用 ansible-galaxy init 指令建立 Role 時會一并產(chǎn)生的檔案之一。
  2. 使用 Markdown 格式編寫。
  3. 內(nèi)容會顯示在 README 頁面里:在 Galaxy 上看到的樣子與 GitHub 相同。
$ 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 Data (meta/main.yml)

  1. 使用 ansible-galaxy init 指令建立 Role 時會一并產(chǎn)生的檔案之一。
  2. 使用 YAML 格式編寫。
  3. 內(nèi)容會顯示在 Details 頁面里面。
$ 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。

Dependencies

  1. 若相依于其它的 role,請于 meta/main.yml 的 dependencies 下方補(bǔ)上。
  2. 使用 YAML 格式編寫。
  3. 關(guān)于 Role Dependencies 可參考 Playbook Roles and Include Statements | Ansible Documentation 一文。
$ cat meta/main.yml
...
dependencies:
  - williamyeh.nginx
  - chusiang.php7
  - geerlingguy.mysql

▲ 此為 chusiang.testlink role 的 meta/main.yml。

以上就是要上傳到 Galaxy 前該特別留意的地方,下章凍仁將講解怎么把 Roles 上傳至 Galaxy。

相關(guān)連結(jié)


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號