Ignore handlers (the Molecule way?) #2771
Replies: 7 comments 1 reply
-
Would you have a runnable sample repo to demonstrate your use case ? I think that would help the discussion. |
Beta Was this translation helpful? Give feedback.
-
An example would be that the interfaces/IPs are not available in my Podman container I use to test my playbook. Creating an interface with e.g. the name 'eth0' and a certain IP like 192.168.1.1/24 is possible I guess? But I'm not sure if that's true for Podman. Therefore, I would like to run the tasks that setup the configuration files for e.g. Postfix, Apache, Dovecot, etc. But not restart the service or run any kind of handler that does any system check, such as e.g. So, as an example, a few handlers:
These are triggered by tasks, which I do want to run, because I want to check them for errors. But because there is a notify there, it will start it, or do some other action that will trigger an error when the handler is run at the end of the playbook. Tags inside handlers are ignored (as it seems, which makes sense since they're called via notify/listen). I don't want to ignore the tests for these tasks, since I do want to check for errors, but simply not start these services via notify/listen. So my question is, is this the way someone should handle these kind of things? A runnable sample would be anything that notifies the above handlers. But maybe it would be an idea to investigate how far I can go with the creation of interfaces with Molecule + Podman. But compared to Docker, it seems limited with Podman. If more info is needed then I'm happy to provide it. |
Beta Was this translation helpful? Give feedback.
-
I will preface this with I have not used podman in the context of molecule, so I will be doing that to understand the differences you mention here. I think I understand what you are asking and what you want to do - but it may be to refactor you roles? When testing a role, part of it is also to test the handlers (to make sure they trigger properly). Since you are looking for potential alternatives - I tried this ( https://github.com/alainchiasson/molecule-issue-2771 ) using a second role with only a handler. As handlers are global, if you call it with the same name, you override it ( on import_role ). You could setup 2 scenarios - one that includes the override scenarios and one that does not. Thoughts ? ( I used one of the later Quay images - 3.06 ) |
Beta Was this translation helpful? Give feedback.
-
It's an interesting solution indeed. It would require some recurring maintenance over time, to see if the overlay role which overrides the handlers is still reflecting the role that's being tested. I see that as a slight downside, the existing solutions to ignore certain tasks by tagging them with Molecule specific names has my preference. But since handlers don't seem to use tags, a when condition is then more consistent with that and doesn't require extra Molecule setup. But I may change my mind about that. I've done some checking with Podman (I never used Docker with Molecule). I don't think I can name network interfaces inside the container's namespace. Now it's tap0 by default. It would be cool if I could name it eth0 (to test e.g. a Raspberry Pi setup). Or even create some extra interfaces an Ansible playbook expects to find. But the code doesn't refer to anything like that, to add and label/alias interfaces. So I guess I should either change to Docker and try that, or use Vagrant. Both are not attractive. I like how Podman works and the lightweight concept of containers. |
Beta Was this translation helpful? Give feedback.
-
I understand not wanting extra maintenance. I started reading on podman networking - its really shifting from a "developer" environment to an "operational" one. I have to experiment more to understand. But if I understand, you are testing roles in molecule/podman but the actual roles run on "full os" (vm/bare metal)? And as such you have a discrepancy with what services can start ( or you just don't want to ) How would you see this implemented ? |
Beta Was this translation helpful? Give feedback.
-
That's right. The Podman environment is missing the interface names and/or IP addresses that services are bound to. For example Dovecot and Apache are set to listen to a specific IP. When that IP is not available in the testing environment (Podman), the socket can't be created and thus the services fails to start. Or in some instances, a A solution could be to have either the ability to setup the networking in more detail (in Podman), i.e. interface names and IPs. Or, add a tag to a task which then disables the notify/listen configuration of that task, e.g. molecule-nohandler. If those solutions aren't possible/pretty, then simply using |
Beta Was this translation helpful? Give feedback.
-
Thanks for the additional information, it helps the to understand. |
Beta Was this translation helpful? Give feedback.
-
Issue Type
Molecule and Ansible details
Molecule installation method (one of):
Ansible installation method (one of):
Desired Behavior
When running tasks, a tag can be defined to either ignore it in Molecule as a test or for idempotency. But for handlers there is no such thing. I use at the moment
when: molecule_yml is not defined
. This is sufficient. But I wonder if there are better (builtin) ways. Because this when condition could also be used instead of using tags I guess. The reason I don't ignore the task that triggers the handler is because I want to test things as much as possible. So if the task itself can be tested, but only the handler needs to be skipped, then I prefer that. Just wondering if I can do this 'better'. I don't find information about ignoring handlers in the docs.Beta Was this translation helpful? Give feedback.
All reactions