Execution flow on role dependencies

21 views
Skip to first unread message

Vonpupp

unread,
Nov 9, 2015, 11:43:29 AM11/9/15
to Ansible Project
Hello,

I'm new to Ansible and I'm building two roles: Haevas.yaourt [1] and Haevas.powerpill [2] to install and configure yaourt and powerpill on Arch Linux. Powerpill is installed via yaourt, then I'm adding the Haevas.yaourt as a dependency for it. At the same time Haevas.yaourt depend on a third role: knopki.sudoers for sudo superpowers.

My question is, what is the "entry point" (or the main execution code if you will) of a dependency? Let me try to further elaborate my question. I'm using travis for CI and a docker script for local testing. Test.yml [3] and site.yml of Haevas.yaourt look like this:

---
- hosts: all
  roles:
    - { role: knopki.sudoers,
        sudoers_filename: "{{ yaourt_makepkg_user }}",
        sudoers_nopasswd: true,
        sudoers: "{{ _sudoers_yaourt_makepkg_user }}"
      }

    - { role: knopki.sudoers,
        sudoers_filename: "travis",
        sudoers_nopasswd: true,
        sudoers: "{{ _sudoers_yaourt_travis_user }}",
        when: is_travis
      }

  tasks:
    - include: tasks/main.yml

  handlers:
    - include: handlers/main.yml

  vars_files:
    - defaults/main.yml

Haevas.yaourt works fine by itself. All the variables are defined in the defaults/main.yml. However when I add it as a dependency on the Haevas.powerpill role it doesn't work. Here is how the test.yml [4] of Haevas.powerpill looks like:

---
- hosts: all
  roles:
    - { role: Haevas.yaourt, yaourt_sync_deps: no }

  tasks:
    - include: tasks/main.yml

  handlers:
    - include: handlers/main.yml

  vars_files:
    - defaults/main.yml 

As you can see I'm not passing the variables since I'm assuming that when Haevas.yaourt will be executed as a dependency it will load the variables by itself. Here is a part of my defaults/main.yaml [5] of Haevas.powerpill:

yaourt_makepkg_user: "{{ powerpill_yaourt_user }}"

_sudoers_yaourt_makepkg_user:
  - name: "{{ yaourt_makepkg_user }}"
    users: ["ALL"]

_sudoers_powerpill_travis_user:
  - name: "travis"
    users: ["ALL"]

At first I did not include these variables since the are defined already in Haevas.yaourt, but since it wasn't working I thought this might solve the problem so I'm repeating the variables and I'm having the following error (same error as if I don't include those variables):

fatal: [local] => One or more undefined variables: 'sudoers_filename' is undefined

FATAL: all hosts have already failed -- aborting

sudoers_filename is defined in the Haevas.yaourt/site.yml (and the test). It is passed as an argument to the third role (knopki.sudoers), however when I call Haevas.yaourt from within Haevas.powerpill it doesn't "see" the variables. What I would like is when the role executes Haevas.yaourt, that it is "self contained" (like if it was executing the site.yml or test.yml). It is possible to do that? What is the "entry point" (or main task if you will) of a role when it is executed as a dependency?

I have no clue what is going on. I believe is something related to "local" and "global" variables. I'm trying to build roles as small as possible to allow reuse and test them, but I cannot properly reuse my own roles.

Sorry for the long email, I tried to explain everything as details as I could.

Thank you very much.
Cheers.

Reply all
Reply to author
Forward
0 new messages