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

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

问题描述

我有一个组织如下的剧本(为了这个问题而简化):

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

这失败了:

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

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

So I tried to change roles/web/tasks/main.yml to

---
- 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 并且有效,但它在 roles/web/tasks/main.yml 之前执行代码>各种工作,我需要在之后执行它.如何做到这一点?

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:

<代码>- 名称:我不再有问题的东西变成:是include_role:名称:davidedelvento.nbextensionwith_items:- 富- 酒吧循环控制:loop_var: 名称

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

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