ansible常用模块 -- include模块 -- 包括一个play或任务列表

ansible常用模块 -- include模块 -- 包括一个play或任务列表

include模块 – 包括一个play或任务列表

一、摘要

  • 包含一个文件,其中包含当前剧本中要执行的剧本或任务的列表。
  • 带有play列表的文件只能包含在顶层。任务列表只能包含在任务正常运行的地方(在play中)。
  • 在Ansible 2.0之前,所有的include都是“静态的”,在剧本编译时执行。
  • 静态包含不受大多数指令的约束。例如,将循环或条件应用于每个继承的任务。
  • 从Ansible 2.0开始,任务包含是动态的,行为更像真实的任务。这意味着它们可以循环、跳过和使用来自任何源的变量。Ansible尝试自动检测,但你可以使用静态指令(这是在Ansible 2.1中添加的)来绕过自动检测。
  • Windows目标也支持此模块。

二、参数

参数选项/默认值描述
free-form这个模块允许您直接指定文件名,而不需要任何其他选项。

三、示例

- hosts: localhost
  tasks:
    - debug:
        msg: play1

- name: Include a play after another play
  include: otherplays.yaml


- hosts: all
  tasks:
    - debug:
        msg: task1

    - name: Include task list in play
      include: stuff.yaml

    - debug:
        msg: task10

- hosts: all
  tasks:
    - debug:
        msg: task1

    - name: Include task list in play only if the condition is true
      include: "{{ hostvar }}.yaml"
      static: no
      when: hostvar is defined

官方文档:https://docs.ansible.com/ansible/2.9/modules/include_module.html#include-module

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值