当我加入角色扮演书

时间:2020-11-05 10:44:29

标签: ansible

我的剧本目录结构。

/ansible_repo/
└── playbooks/
    ├──playbooks1.yml
    ├──playbooks2.yml
├── somerole.yml  --> main playbook with roles
└── roles/
    └── somerole
        ├── default
        │   └── main.yml
        ├── handler
        │   └── main.yml
        ├── tasks
        │   └── main.yml
        └── vars
            └── main.yml

playbooks1.yml:

---
- hosts: all
  tasks:
    - pause:
        minutes: 3
    - name: ping host
      win_ping:

somerole.yml:

---
- hosts: ci_host
  roles:
    - somerole

somerole \ tasks \ main.yml:

---
- include: playbooks/playbooks1.yml

当我在某个主机上运行该角色时:

ansible-playbook role-test.yml -vv --limit somehost

我收到此错误:

fatal: [somehost]: FAILED! =>
  reason: |-
    conflicting action statements: hosts, tasks

如果我改变了它过去的样子:

- pause:
  minutes: 3
- name: ping host
  win_ping:

我试图了解如何在role-tasks-main和playbook.yml中设置主机和任务 并将剧本包含在角色任务中。

如果发生冲突,我可以配置层次结构主机吗?

1 个答案:

答案 0 :(得分:0)

该错误表明您正在角色中包含一本剧本,并且角色hoststasks不允许。

由于somerole.yml是您的主要剧本,因此您可以根据需要调用其他剧本和角色。

示例:

- name: run playbook playbook1
  import_playbook: playbooks/playbooks1.yml

- hosts: ci_host
  roles:
    - somerole

- name: run playbook playbook2
  import_playbook: playbooks/playbooks2.yml