Search code examples
ansibleroles

Second ansible role not running in playbook


I am experimenting with using roles in a playbook. My simple playbook is as follows:

---
  - name: Simple playbook
    hosts: all
    tasks:
    - name: Role1
      include_role:
        name: role1
      vars:
        debugmode : true
    - name: Role2
      include_role:
        name: role2
      vars:
        debugmode : true

I run the playbook with -vvv and I see all of my role1 tasks run. However, role2 tasks don't run, I just see this output (excerpt):

TASK [Role2] *********************************************************************************************************************************************************************************************************************************************************
task path: /myplaybook.yml:10
META: ran handlers
META: ran handlers

my my role2/tasks/main.yml file is:

  - debug:
    msg: "In create_vms role"

Solution

  • Although the cause of the problem is rather silly, I suspect this may help someone else.

    The problem was that my file was accidentally named

    role2/tasks/mail.yml

    (not main.yml).

    So ansible had no problem with this, it just ignored the file and did nothing. Seems like ansible should raise some kind of warning if no files are found in a role, so check for a typo :)