3.2. Playbook を使用した自動化コンテンツの作成
Ansible Playbook は、どのデバイスでどのタスクを実行するかを Ansible Automation Platform に指示するブループリントです。Playbook を使用して、プラットフォームで実行する自動化タスクを定義できます。
3.2.1. Playbook の作成
Playbook には 1 つ以上のプレイを含めます。基本的なプレイには、次のパラメーターを含めます。
- 名前: Playbook の全体的な機能の簡単な説明。これにより、Playbook をすべてのユーザーにとって理解しやすく整理されたものにすることができます。
- ホスト: Ansible を実行するターゲットを示します。
-
become ステートメント: これは任意のステートメントです。
true
またはyes
に設定すると、become プラグイン (sudo
、su
、pfexec
、doas
、pbrun
、dzdo
、ksu
など) を使用して権限昇格を有効にできます。 - タスク: これは、プレイ内の各ホストに対して実行されるアクションのリストです。
以下は Playbook 内のプレイの例です。プレイの名前、ホスト、プレイに含まれるタスクのリストを確認できます。
- name: Set Up a Project and Job Template hosts: host.name.ip become: true tasks: - name: Create a Project ansible.controller.project: name: Job Template Test Project state: present scm_type: git scm_url: https://github.com/ansible/ansible-tower-samples.git - name: Create a Job Template ansible.controller.job_template: name: my-job-1 project: Job Template Test Project inventory: Demo Inventory playbook: hello_world.yml job_type: run state: present
- name: Set Up a Project and Job Template
hosts: host.name.ip
become: true
tasks:
- name: Create a Project
ansible.controller.project:
name: Job Template Test Project
state: present
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples.git
- name: Create a Job Template
ansible.controller.job_template:
name: my-job-1
project: Job Template Test Project
inventory: Demo Inventory
playbook: hello_world.yml
job_type: run
state: present
Playbook の作成に関する詳細な手順は、自動化コンテンツの開発 を参照してください。または、AI アシスタンスを使用して Playbook を生成する方法は、Red Hat Ansible Lightspeed with IBM watsonx Code Assistant ユーザーガイド ドキュメントを参照してください。