Coder Social home page Coder Social logo

Comments (6)

drybjed avatar drybjed commented on August 23, 2024

My first guess would be that it is dependent on the order of variable/task resolution in Ansible. IIRC, before Ansible touches the tasks in any way, all variables are resolved first, including lookups.

In the test_fail.yml playbook, the lookup is resolved by Ansible too late, it wants to run all tasks at this point. Not sure what's exactly happening there, you could add a register to that task and debug the output.

In the test_success.yml playbook, Ansible first resolves the play variables, so it has a chance to properly perform the lookup. Next, the task already has the correct path from the lookup so Ansible can process it and include other tasks as you expect.

Remember, that in DebOps, all lookups using custom hooks are performed on the role level, not on the playbook level. IIRC this has its own rules regarding variable/task resolution by Ansible, and that's the reason these lookups work in the roles.

from debops-tools.

vshalts avatar vshalts commented on August 23, 2024

The same issue appear if hook called from debops.users role. It was the first things I tried. This example was my attempt to create simplified version.
Here is updated example that based on roles: https://www.dropbox.com/s/n2z14b0a35i1j77/debops-test_1.zip?dl=0

As I understand it is impossible to call another role from hook, right? So, the only way to split code called in hook that I see is to use includes. What happens: lookup itself work fine and include code from hook (post_main), but if hook itself has include task - include will be ignored (no error messages :( ). So, include from inside hook doesn't work (including case when hook was called from role), but all tasks from hook prior to this include task will work as expected.

I will be glad for any solution/example where hook code spitted into several files. I will appreciate If you point me to any example code where such splitted hook demonstrated. Thanks.

from debops-tools.

drybjed avatar drybjed commented on August 23, 2024

You're correct, the lookup plugins aren't recursive, so includes present in the included task list won't work. Fixing that would probably require copying at least some code from Ansible that handles include parsing and I think this is outside of the scope of these plugins.

You cannot include other roles using lookup plugins as well, this is meant only for task lists. The task_src lookup plugin was meant to be used to "inject" 2-3 tasks from a file somewhere, in a case where you don't want to write a custom role that replaces the one you are trying to "augment". From your case it seems that you want to extend debops.users beyond what task_src does, so I would just write a replacement debops.users role and put it in the DebOps project directory, in ansible/roles/. That way it should "mask" the default debops.users and let you easily do what you want.

from debops-tools.

vshalts avatar vshalts commented on August 23, 2024

I see. I am not realized that it is possible to "mask" default roles. That solution will work for me too. Probably will need to merge changes from time to time, but it is ok. Thanks!!

from debops-tools.

drybjed avatar drybjed commented on August 23, 2024

@vshalts Great. One of the core ideas of DebOps is that roles and playbooks are "read-only" to allow updates using git, therefore there should always be a way to allow user customization. Using roles_path variable to "mask" roles with your own custom ones is one such method of doing that. It's not always perfect, especially when you access things outside of the role itself, so I try not to do that and use different methods to pass data between roles.

from debops-tools.

vshalts avatar vshalts commented on August 23, 2024

I'll try my best :) Thanks for suggestion!!

from debops-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.