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.

[1]: https://github.com/Haevas/Haevas.yaourt
[2]: https://github.com/Haevas/Haevas.powerpill/tree/feature/initial_commit
[3]: https://github.com/Haevas/Haevas.yaourt/blob/master/test.yml
[4]: 
https://github.com/Haevas/Haevas.powerpill/blob/feature/initial_commit/test.yml

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fc368c47-dec7-4ec6-84ee-7e6b02c3cad5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to