playbook文件复用介绍

include_tasks用来动态的包含tasks任务文件,也可以使用import_playbook导入playbook文件

注意task只是任务,而playbook则是一个完整的文件

# 主入口文件
cat 24.yml 
- hosts: all
  remote_user: root
  tasks:
    - include_tasks: 25.yml
    - include_tasks: 26.yml

# 25.yml
cat 25.yml 
- name: create /file1
  command: touch /file1
# 26.yml
cat 26.yml 
- name: create /file2
  command: touch /file2

ansible-playbook 24.yml
posted @ 2025-08-23 20:41  阿峰博客站  阅读(11)  评论(0)    收藏  举报