📘
現代 IT 人一定要知道的 Ansible 自動化組態技巧
  • README
  • 前言
  • Ansible 是什麼?
  • 怎麼部署 Ansible 環境?
  • 怎麼用 Vagrant 練習 Ansible?
  • 怎麼用 Docker 練習 Ansible?
  • 怎麼操作 Ansible?
  • 怎麼用 Jupyter 操控 Ansible?(localhost)
  • 怎麼用 Jupyter 操控 Ansible?(Managed node)
  • 怎麼用 Docker Compose 練習 Ansible?
  • Ansible 的開發工具有哪些?
  • 怎麼看 Ansible Modules 文件?
  • 常用的 Ansible Module 有哪些?
  • 怎麼使用 setup 取得 Managed node 的 facts?
  • 怎麼使用 Ansible 的 Template 系統?
  • 怎麼在 Playbooks 裡使用 Handlers?
  • Ansible 如何發送 notification 到 Slack?
  • Ansible 如何發送 notification 到 HipChat?
  • 如何在 Playbooks 使用 loops?
  • 如何維護大型的 Playbooks?
  • Roles 是什麼?
  • 怎麼使用 Roles?
  • 怎麼用 Roles 部署 LNMP 網頁應用程式?(上)
  • 怎麼用 Roles 部署 LNMP 網頁應用程式?(下)
  • 怎麼用 Roles 部署 TestLink?
  • 怎麼在 Ansible Galaxy 分享 Roles?(上)
  • 怎麼在 Ansible Galaxy 分享 Roles?(下)
  • 怎麼用 Travis CI 測試 Roles?
  • 怎麼混用 Ansible 建置 Docker image?
  • 怎麼在 Docker Hub 混用 Ansible 自動建置 Docker image?
  • 怎麼用 Vault 管理敏感資料?
  • 總結
Powered by GitBook
On this page
  • 21. 怎麼使用 Roles?
  • 什麼是 Galaxy?
  • ansible-galaxy 是什麼?
  • 怎麼用 Galaxy 搜尋 Roles?
  • 怎麼用 ansible-galaxy 搜尋 Roles?
  • 怎麼安裝 Roles?
  • 怎麼初始化 Roles?
  • 後語
  • 相關連結

Was this helpful?

Edit on GitHub

怎麼使用 Roles?

PreviousRoles 是什麼?Next怎麼用 Roles 部署 LNMP 網頁應用程式?(上)

Last updated 5 years ago

Was this helpful?

21. 怎麼使用 Roles?

上一章「」凍仁簡單介紹了 Roles,接下來重頭戲登場囉!

什麼是 Galaxy?

ansible-galaxy 是什麼?

ansible-galaxy 是管理 Roles 的指令,我們可以在 Terminal 裡用它搜尋 (search)、安裝 (install)、移除 (remove) Roles 等。換句話說它是 Ansible 世界的 pip。

想深入了解 ansible-galaxy 的話,不妨 man 一下它!

$ man ansible-galaxy

怎麼用 Galaxy 搜尋 Roles?

  1. 進到 Galaxy 的網站後,可在右上角的 Browser Roles 找到數不完的 Role。

  1. 在 Keyword 一欄輸入關鍵字後,接下 Enter 即可搜尋。底下將以 win_vim role 為例。

  1. 在 Details 頁籤裡,可以看到關於這個 Role 的版本記錄 (Version History)、支援的平台 (Supported Platforms) 等資訊。

Ansible 最小支援版本 (Minimum Ansible Version) 的部份也請留意,有些語法在舊版的 Ansible 是不被支援的喔!

  1. 在 README 頁籤裡,可以看到作者寫的說明文件。一般會在 Role Variables 底下列出哪些可以被覆寫的預設變數。

怎麼用 ansible-galaxy 搜尋 Roles?

除了在 Galaxy 網站搜尋 Roles 以外,我們也可以使用 ansible-galaxy search + 關鍵字進行搜尋。

怎麼安裝 Roles?

怎麼初始化 Roles?

以上,您學會怎麼使用 Roles 了嗎?下章凍仁將教大家如何利用 Galaxy 上的 Roles 建置 LNMP 環境。

後語

我們除了可以在 Galaxy 找到現成的 Roles 外,更可藉由閱讀前人的 source code 來學習各種知識與技巧。

倘若覺得別人的 Roles 不好使,您就自己寫一個,然後分享出來吧!

相關連結

我們可以透過 (銀河) 和 ansible-galaxy (Terminal) 來使用 Roles。

的全名為 Ansible Galaxy,它是官方維護的 Roles 市集 (marketplace) 網站。我們可以在網站上取得社群成員所維護的 Roles,其 source code 存放於 GitHub。

開啟瀏覽器 (Browsers) 並進入 。

請使用 ansible-galaxy install + Role 名稱 來安裝 role,如要自訂存放 Roles 的位置,請使用 -p + 路徑,詳情請參考 一文。

我們可以用 ansible-galaxy init + Role 名稱 來建立一個新 role,其檔案結構部份凍仁已在上一章的「」介紹過,這裡就不詳述了。

Galaxy
Galaxy
https://galaxy.ansible.com
Download Roles | Ansible Galaxy
Ansible Galaxy | Find, reuse, and share the best Ansible content
Ansible: Up and Running — an O’Reilly book by Lorin Hochstein
現代 IT 人一定要知道的 Ansible 自動化組態技巧 Ⅱ - Roles & Windows | 凍仁的筆記
20. Roles 是什麼?
Role 的基本結構
automate_with_ansible_roles_and_windows-07.jpg
automate_with_ansible_roles_and_windows-08.jpg
automate_with_ansible_roles_and_windows-09.jpg
automate_with_ansible_roles_and_windows-14.jpg
automate_with_ansible_roles_and_windows-10.jpg
automate_with_ansible_roles_and_windows-11.jpg
automate_with_ansible_roles_and_windows-12.jpg
automate_with_ansible_roles_and_windows-13.jpg
automate_with_ansible_roles_and_windows-15.jpg
automate_with_ansible_roles_and_windows-16.jpg
automate_with_ansible_roles_and_windows-17.jpg