-1

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

My simplified deploy.yml is:

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

And my simplified roles/web/tasks/main.yml is

---
- 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.

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....)

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?

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

EDIT: 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)

EDIT2: 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

Davide
  • 17,098
  • 11
  • 52
  • 68
  • 1
    You are mixing action modules with roles. To the point that I gave up on trying to figure out what you have and what you want. These are two different things. There is no module named `davidedelvento.nbextension` and no module named `role`, so Ansible is right in its error messages. – techraf Sep 06 '17 at 01:33
  • As above I'm not quite sure what you're trying to achieve, but you are confusing a few concepts. I can see that davidedelvento.nbextension is a role in ansible galaxy so I assume you've installed that already (ansible-galaxy install davidedelvento.nbextension). then you should be able to use the notations `roles: davidedelvento.nbextension` – Nick Brown Sep 06 '17 at 16:08
  • @techraf: I'm new to ansible, so I may be well doing something wrong, that's why it does not work and that's why I'm asking here... What I want is very simple: I want an nbextension to be installed (using the galaxy role that I published on the galaxy and linked), after various things are done. So, how do I accomplish that? Since nbextension is a role and this file I posted is a task, and I can't call a role from a task, I think I should do something different but what? – Davide Sep 06 '17 at 19:16
  • @NickBrown please see the additional info I added in the EDIT. As I said, yes, that role is correctly installed and it works when used "separately". However [the documentation](http://docs.ansible.com/ansible/latest/playbooks_best_practices.html) taught me to use the directory structure I'm using and now the web role executes the things in the task directory where I cannot call the nbextension role. What can I do differently to be able to have the nbextension done after the "whatever" things I describe in the question, and still keep things sane (i.e. not giant playbook with everything in it)? – Davide Sep 06 '17 at 19:29
  • This question doesn't show that the role you're trying to install is used anywhere, nor do you appear to be referring to it in a `role:` block anywhere except in your "standalone" example at the end. – larsks Sep 06 '17 at 19:42
  • @larsks I am not trying to install anything. The thing is installed correctly and it works per se. What this question is about is using, not installing the role davidedelvento.nbextension. I am certainly using it incorrectly, but I **am** trying to use that role in both code snippets for `roles/web/tasks/main.yml`. In the first snippet as if it were a module, in the second case explicitly as a role. Please see the code following the sentences "And my simplified roles/web/tasks/main.yml is" and "So I tried to change roles/web/tasks/main.yml to" and see the presence of davidedelvento.nbextension – Davide Sep 07 '17 at 14:21
  • @Davide [According to the README](https://github.com/davidedelvento/ansible-nbextension#example-playbook) the name of the role is `davidedelvento.ansible-nbextension`. Are you sure you are typing the name of the role correctly? – mchristie Sep 11 '17 at 17:35
  • @mchristie Thanks for the suggestion. The README was wrong and I've just fixed it. As I note in the question, the standalone playbook works just fine (and it doesn't if I use the `davidedelvento.ansible-nbextension` name). The whole problem here is **how to use a role from a multi-file playbook** – Davide Sep 11 '17 at 18:03
  • @Davide Ok, so I think the crux of the problem is that **you need a way to call a role from within another role**. Specifically you need a way to call the `davidedelvento.nbextension` role from within the `web` role. Traditionally you couldn't call a role from another role, see [this answer about how to do it in Ansible 2.2+](https://stackoverflow.com/a/39936933/1419499). *Looks like you already found the `include_role` module.* – mchristie Sep 11 '17 at 20:57

1 Answers1

0

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

  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

Davide
  • 17,098
  • 11
  • 52
  • 68