第 6 章 创建内容
使用创建器指南一节中的指南,了解更多有关开发 Red Hat Ansible Automation Platform 中使用的内容的信息。
6.1. 创建 playbook
Playbook 包含一个或多个 play。基本 play 包括以下部分:
- Name:对 playbook 整体功能的简短描述,有助于保持所有用户的可读性和组织性。
- Hosts:识别要针对 Ansible 运行的目标。
-
Become 声明:这个可选声明可以被设置为
true
/yes
来使用一个 become 插件 (如sudo
,su
,pfexec
,doas
,pbrun
,dzdo
,ksu
) 进行权限升级。 - Tasks:这是对 play 中每一主机执行的列表操作。
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