SiliconMind
SiliconMind

Reputation: 2179

Why ansible silently ignores a role?

I have a playbook that requires few roles to run first but for some reason ansible is persistently ignoring one of the roles without any output.

Example playbook:

---
- hosts: mirrors
  roles:
    - timezone
    - console
    - core
    - nginx-reverse-proxy

Role nginx-reverse-proxy requires nginx role, so file roles/nginx-reverse-proxy/meta/main.yml contains:

---
# Dependencies required for nginx-reverse-proxy role

dependencies:
  - nginx

When I run the playbook like this: ansible-playbook -i mirrors/hosts.yml mirrors/playbook.yml, ansible reaches nginx-reverse-proxy role and then immediately starts executing tasks from roles/nginx-reverse-proxy/tasks/main.yml completely ignoring nginx role from roles/nginx-reverse-proxy/meta/main.yml.

What I tried:

  1. Putting nginx role directly to the playbook after core and before nginx-reverse-proxy - ansible ignored nginx role and skipped immediately to nginx-reverse-proxy.
  2. Putting some gibberish to roles/nginx/tasks/main.yml to see what happens, but ansible doesn't even try to execute it. There is no error like it doesn't even try to parse the file.
  3. Running ansible-playbook with -vvvv switch, but it didn't tell me anything useful.
  4. The nginx role itself has few files inside roles/nginx/tasks/ directory. All are yml files that are included in roles/nginx/tasks/main.yml conditionally like this:

    ---
    - include: install_nginx_core.yml
      when: not nginx_extras
    
    - include: install_nginx_extras.yml
      when: nginx_extras
    
    - include: setup_ssl.yml
    
    - include: setup_fastcgi.yml
      # This will also install php5-fpm
      when: setup_fastcgi
    

    I removed those files to see if this changes anything, but no luck.

I'm not using any additional switches to run the playbook and it was working fine around version 2.0. But now I'm on 2.1.2.0 and I'm stuck.

[Edit] Including output of tree roles/nginx:

roles/nginx
|-- defaults
|   `-- main.yml
|-- meta
|   `-- main.yml
|-- tasks
|   |-- install_nginx_core.yml
|   |-- install_nginx_extras.yml
|   |-- main.yml
|   |-- setup_fastcgi.yml
|   `-- setup_ssl.yml
`-- templates
    |-- fastcgi.j2
    `-- ssl.conf

Upvotes: 2

Views: 2339

Answers (2)

xorinzor
xorinzor

Reputation: 6467

I had a similar issue while using Ansible Automation Platform (AAP). Turns out I created my templates and assigned them job_tags, mistakenly thinking that was meant for organizing the templates & tasks it created.

Instead it passed them along to the playbook that was executing, thus only selecting tasks from the roles that had those tags assigned.

TLDR: Verify you're not selecting tags (or selecting the wrong tags) for tasks

Upvotes: 0

PolyTekPatrick
PolyTekPatrick

Reputation: 3142

I had a similar problem with ansible silently ignoring my role. Turned out that I goofed and I had my file at roles/myrolename/main.yml instead of the proper roles/myrolename/tasks/main.yml

This may not be the issue that OP had, but I hope this saves someone else the time I wasted banging my head on this stupid mistake.

Upvotes: 5

Related Questions