附註:
- 此教學課程可在 Oracle 提供的免費實驗室環境中取得。
- 它使用 Oracle Cloud Infrastructure 證明資料、租用戶及區間的範例值。完成實驗室時,請將這些值取代為您雲端環境特定的值。
使用 AWX 集合管理 Oracle Linux Automation Manager
簡介
AWX Ansible 集合可讓管理員透過手冊與 Oracle Linux Automation Manager 互動。這些模組包括執行使用者和群組管理、建立專案以及執行工作等工作的能力。
目標
在本教學課程中,您將瞭解如何:
- 部署 DevOps 和 Oracle Linux Automation Manager 執行處理
- 設定 DevOps 執行處理上的組態檔
- 撰寫手冊以建立執行工作的必要項目
- 測試並檢查手冊
必要條件
- 用於執行 Oracle Linux Automation Engine 手冊的控制節點
- Oracle Linux Automation Manager 執行處理
部署 Oracle Linux Automation Manager
注意:如果在您自己的租用戶中執行,請先閱讀 linux-virt-labs
GitHub 專案 README.md 並完成先決條件,再部署實驗室環境。
-
在 Luna 桌面上開啟終端機。
-
複製
linux-virt-labs
GitHub 專案。git clone https://github.com/oracle-devrel/linux-virt-labs.git
-
變更至工作目錄。
cd linux-virt-labs/olam
-
安裝所需的集合。
ansible-galaxy collection install -r requirements.yml
-
更新 Oracle Linux 執行處理組態。
cat << EOF | tee instances.yml > /dev/null compute_instances: 1: instance_name: "olam-node" type: "control" olam_type: single EOF
-
建立產品目錄檔案。
cat << EOF | tee hosts > /dev/null localhost ansible_connection=local ansible_connection=local ansible_python_interpreter=/usr/bin/python3.6 EOF
-
部署實驗室環境。
ansible-playbook create_instance.yml -i hosts -e "@instances.yml"
免費實驗室環境需要額外的 localhost
ansible_python_interpreter
變數,因為它會為 Python 適用的 Oracle Cloud Infrastructure SDK 安裝 RPM 套件。安裝此套裝軟體的位置位於以您 Oracle Linux 版本為基礎的系統預設 Python 模組底下。使用產品目錄變數可避免影響 localhost 以外的主機上執行的播放。預設部署資源配置使用 AMD CPU。您可以在命令行中傳送新的資源配置變數定義,以變更執行處理的資源配置。
例如:
-e instance_shape="VM.Standard3.Flex"
同樣地,Oracle Linux 映像檔的預設版本會使用 `default_vars.yml 檔案中定義的變數
os_version
。您可以在命令行中傳送 Oracle Linux 主要版本,即可修改這個值。例如:
-e os_version="9"
重要事項: 請等待播放手冊順利執行,然後到達暫停工作。在手冊的這個階段,Oracle Linux 的安裝已完成,實例已就緒。請注意,上一個播放會列印其部署節點的公用和專用 IP 位址。
驗證 Oracle Linux Automation Manager 部署
-
開啟新終端機。
-
設定 Oracle Linux Automation Manager 執行處理的 SSH 通道。
ssh -o ExitOnForwardFailure=yes -f -L 8444:localhost:443 oracle@<public_ip_address_of_olam-node> sleep 300
-o ExitOnForwardFailure=yes
:等待所有遠端連接埠轉寄成功建立-f
:在背景中執行 SSH 通道-L
:在本機系統上的連接埠 8444 和遠端系統上建立通道 443sleep 300
:讓遠端通道保持開啟 5 分鐘,等待已建立的連線再自動關閉
-
開啟 Web 瀏覽器並輸入 URL。
https://localhost:8444
注意:根據使用的瀏覽器來核准安全警告。若為 Chrome,請按一下
Advanced
按鈕,然後按一下Proceed to localhost (unsafe)
連結。 -
使用使用者名稱
admin
和部署期間建立的密碼admin
登入 Oracle Linux Automation Manager。 -
登入之後,會顯示 Web UI。
建立控制器組態檔
AWX Ansible 集合使用組態檔,在某些情況下,AWX CLI 會根據 Oracle Linux Automation Manager 進行認證。您可以使用 CLI 直接在命令行中傳送認證參數,或寫入組態檔。
指定認證參數時,「AWX Ansible 集合」應為下列其中一項組合:
- 主機,使用者名稱,密碼
- 主機,OAuth2 記號
如需更多詳細資訊,請參閱上游專案。
-
返回您建立 SSH 通道的終端機。
-
產生組態檔。
cat << EOF | tee ~/.tower_cli.cfg > /dev/null [general] host: https://localhost:8444 verify_ssl: false username: admin password: admin use_token = false EOF
host:
- 定義存取 Oracle Linux Automation Manager Web UI 的 URLverify_ssl:
- 關閉嚴格的 SSL 檢查,因為教學課程環境使用自行簽署的憑證use_token:
- 雖然偏好使用 OAuth2 記號,但設為 false 會使用一個記號來進行認證
建立組織
在開始使用教學課程中,組織位於角色型金字塔的頂端,是使用者、團隊、專案和庫存的邏輯集合。
我們可以撰寫手冊,而不是透過 Web UI 來建立。
-
撰寫手冊。
cat << EOF | tee configure-olam.yaml > /dev/null --- - name: Playbook to set up training demo data using the AWX collection hosts: localhost gather_facts: false collections: - awx.awx tasks: - name: Create an organization awx.awx.organization: name: "Example" description: "Created using a playbook" state: present EOF
-
執行此手冊 。
ansible-playbook configure-olam.yaml
-
驗證 Web UI 中的變更。
使用瀏覽器登入 Web UI。
注意:如果發生登入失敗,SSH 通道可能已經過期。在此情況下,您必須重新執行 SSH 命令才能重新建立連線。
按一下導覽功能表中的組織。請注意建立手冊的範例項目。
執行工作
建立「組織」之後,現在讓我們在開始使用教學課程中自動執行其餘步驟,並進行一些修改。Oracle Linux Automation Engine 的其中一項優點就是自行撰寫文件。
-
回到您建立了該手冊的終端機。
-
將額外的設定附加到現有的手冊 。
cat << EOF | tee -a configure-olam.yaml > /dev/null - name: Add a user awx.awx.user: username: jdoe password: oracle email: jdoe@example.com first_name: John last_name: Doe organization: Example state: present - name: Add an inventory awx.awx.inventory: name: "Demo Inventory" description: "Demo OCI Instances" organization: Example state: present - name: Add a host awx.awx.host: name: localhost description: "Use to run tasks locally" inventory: "Demo Inventory" state: present variables: ansible_connection: local - name: Add a credential awx.awx.credential: name: "Linux Instance" credential_type: Machine organization: Example inputs: username: opc ssh_key_data: "" - name: Add a project awx.awx.project: name: "Hello World" description: "Sample Hello World Project" organization: Example default_environment: "OLAM EE (2.3)" scm_type: "git" scm_update_on_launch: false scm_url: https://github.com/oracle-devrel/linux-virt-labs.git state: present - name: Add a template awx.awx.job_template: name: "Say Hello" job_type: "run" organization: Example inventory: "Demo Inventory" project: "Hello World" playbook: "labs/olam-hello-world.yaml" state: present - name: Launch a job awx.awx.job_launch: job_template: "Say Hello" wait: true register: job - name: Print results from job ansible.builtin.debug: var: job EOF
-
重新執行手冊。
ansible-playbook configure-olam.yaml
播放手冊的結尾是最後一個顯示工作狀態為
successful
的播放,還有一個可以忽略的警告。 -
在 Web UI 中驗證工作。
使用瀏覽器,瀏覽至工作,然後按一下說您好工作。輸出會顯示工作期間播放簿執行的結果。請注意除錯工作的歡迎訊息。
接下來的步驟
Web UI 內的輸出會確認您有使用中的 Oracle Linux Automation Manager,並已撰寫手冊來管理部分更常見的任務。
相關連結
其他學習資源
探索 docs.oracle.com/learn 上的其他實驗室,或存取 Oracle Learning YouTube 頻道上的更多免費學習內容。此外,請造訪 education.oracle.com/learning-explorer 以成為 Oracle Learning Explorer。
如需產品文件,請造訪 Oracle Help Center 。
Manage Oracle Linux Automation Manager Using the AWX Collection
G32880-02
Copyright ©2024, Oracle and/or its affiliates.