Ansible(二十一)-- ansible中导入剧本(import_playbook)和导入任务(import_tasks)

一、导入剧本(import_playbook)

注意:导入的剧本必须要写完整,包括hosts、tasks

1、写导入的剧本import_playbook.yml

vim import_playbook.yml
---
- name: this is import_play
  hosts: servera
  tasks:
    - name: install httpd
      yum:
        name: httpd
        state: latest
        

2、写主要playbook.yml

vim playbook.yml
---
- name: import
  import_playbook: import_playbook.yml
- name: this is main_play
  hosts: servera
  tasks:
    - name: start httpd
      service:
        name: httpd
        state: started
        enabled: yes

二、导入任务(import_tasks)

1、写导入任务(import_tasks)

vim import_tasks.yml
---
 - name: install httpd
   yum:
     name: httpd
     state: latest
        

2、写主要playbook.yml

vim playbook.yml
---
- name: this is main_play
  hosts: servera
  tasks:
    - name: import
      import_tasks:import_tasks.yml

你可能感兴趣的:(企业实战之ansible)