如何使用多文件剧本中的角色 [英] How to use a role from a multi-file playbook

查看:111
本文介绍了如何使用多文件剧本中的角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个剧本,其组织方式如下(为简化此问题而简化):

I have a playbook organized as follows (simplified for the sake of this question):

├── deploy.yml
├── hosts
├── requirements.yml
├── roles
│   └── web
│       ├── meta
│       │   └── main.yml
│       └── tasks
│           └── main.yml
└── site.retry

我的简化的deploy.yml是:

---
- name: Everything I need
  hosts: somewhere
  roles:
    - web

而我的简化roles/web/tasks/main.yml

---
- name: Various things that work
  become: yes
  [whatever]

- name: the thing that I have a problem with
  become: yes
  davidedelvento.nbextension: name=foo state=present

此操作失败,并显示以下信息:

This fails with:

ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

所以我尝试将roles/web/tasks/main.yml更改为

---
- name: Various things that work
  become: yes
  [whatever]

- name: the thing that I have a problem with
  become: yes
  roles:
    - { role: davidedelvento.nbextension, name: foo, state: present}

,以相同的方式失败.我了解失败的原因(因为我无法从任务中调用角色,而是我正在执行的任务-但错误可能会更清楚....)

which fails in the same way. I understand the failure (since I cannot call a role from a task, which instead I'm doing -- but the error could be clearer....)

但是我不清楚如何完成自己想要的事情,即在那个时间点做nbextension正在做的事情.我可以将该角色从roles/web/tasks/main.yml移至roles/web/meta/main.yml,并且可以正常工作,但是它是在Various things that work之前执行的,而我需要在之后执行.如何做到这一点?

However I am not clear how can I accomplish what I'd like, namely doing whatever nbextension is doing at that point in time. I could move that role from roles/web/tasks/main.yml to roles/web/meta/main.yml and that works, but it is executed before the Various things that work and I need it to be executed after. How to accomplish that?

请注意,我写了 nbextension ,但是与星系.

Note that I wrote nbextension, however the same problem happen with similar other roles from the galaxy.

还请注意,扩展程序已正确安装,可以从独立的单文件剧本(如

Note also that the extension is correctly installed and can be used from a standalone, single-file playbook such as

---
- name: Example
  hosts: all
  become: yes
  roles:
    - { role: davidedelvento.nbextension, name: foo, state: present}

无论如何,我需要它来集成"到上述针对网络"角色的较大项目中(我还有很多未显示的角色)

however I need it to "integrate" in the larger project described above for the "web" role (I have more roles that I'm not showing)

请注意,用于此问题的星系ansible角色已重命名为 jupyterextension 但正如我所说,对于任何角色,问题(和解决方案)都是相同的

note that the galaxy ansible role used for this question has been renamed to jupyterextension but as I said the issue (and solution) is the same for any role

推荐答案

好,所以我找到了两种方法来解决此问题.

Ok, so I've found two ways to deal with this issue.

  1. 将角色分为两个(或更多)部分,并使用银河系的角色作为对它需要先决的事物的依赖.总的来说,我喜欢这个想法,但是在我的特定用例中,我不喜欢这个想法,因为我需要为一个真正的角色创建3个角色.
  2. 使用 include_role模块,但需要注意的是标记为预览",即不能保证具有向后兼容的界面.但是,对于我当前的设置,它工作得很好:
  1. split the role in two (or more) parts and use the galaxy's role as a dependency to the things that it needs to prepend. In general, I like this idea, but in my particular use case I don't, since I would need create 3 roles for something that is really one.
  2. Use include_role module, with the caveat that at the moment it is "flagged as preview", namely it is not guaranteed to have a backwards compatible interface. However it works quite well for my current setup:

- name: the thing that I have not a problem with anymore become: yes include_role: name: davidedelvento.nbextension with_items: - foo - bar loop_control: loop_var: name

- name: the thing that I have not a problem with anymore become: yes include_role: name: davidedelvento.nbextension with_items: - foo - bar loop_control: loop_var: name

这篇关于如何使用多文件剧本中的角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆