Playbook contain multiple Plays
Each play contain multiple tasks
Use include module to call and use small/repeatable playbook, make main playbook neat.
Use **include_role module to use pre-defined ROLE and Tasks associated with this role
Role is to load pre-defined tasks, as yaml files, then together with variables 变量
**
import_tasks(Static)方法会在playbooks解析阶段将父task变量和子task变量全部读取并加载
include_tasks(Dynamic)方法则是在执行子task的play之前才会加载自己变量
#tree roles/
.
└── role_ONE
├── README.md # 说明文件
├── defaults
│ └── main.yml # 可被复写的Variable。
├── handlers
│ └── main.yml # 主要的 handler。
├── tasks
│ └── main.yml # 主要的 task。
├── templates # 被tasks中main.yml调用的Jinja2模板, j2 files
└── vars
└── main.yml # 不可被复写的Variable。
└── role_TWO
└── role_FIVE
#ansible-galaxy init sample_role # 创建最佳结构
#ansible-galaxy import predefined_role
- name: Deploy Core SW with role
hosts: core-sw
connection: network_cli
gather_facts: no
roles:
- agg_sw
- switch