Ansible-在include_tasks动作中使用include_role

问题描述 投票:0回答:1

我有一个包含一些任务的文件。该文件中的一项任务使用include_role从角色执行一堆任务。

# tasks.yml

- name: task-1
  include_role:
    name: my-role

- name: task-2
  ...

我有我的主要剧本,它从with_items循环中调用task.yaml中的任务:

# main.yml

tasks:
  - name: main-task
    include_tasks: tasks.yaml
    with_items: "{{ items.values()|list }}"

运行此剧本时出现以下错误:

ERROR! 'include_role' is not a valid attribute for a Play.
The error appears to have been in '.../tasks.yml': line 1, column 3, but may be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
  - name: task-1
    ^ here

Ansible似乎不喜欢在任务文件中使用include_role的方式。我不确定某个地方的语法是否错误,或者是否不支持这种方式。有什么想法吗?

ansible
1个回答
0
投票

首先以动物角色进行测试。我会删除with_items作为第二个选项,可能无法正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.