shane_kerr,
@shane_kerr@fosstodon.org avatar

I'm cleaning up problems reported by ansible-lint and am down to a couple of these:

https://ansible.readthedocs.io/projects/lint/rules/no-handler/

The problem that I have is that if I follow the recommendation and convert the tasks to handlers, then the handlers will be very far away in the playbook - way down at the bottom, hundreds of lines later.

I can silence the error, but I guess it is there for a reason.

Am I crazy? Or is the idea that I should be having smaller playbooks or what?

ascherbaum,
@ascherbaum@mastodon.social avatar

@shane_kerr there is an meta command "flush_handlers" which you can use to force handlers.

nebucatnetzer,
@nebucatnetzer@emacs.ch avatar

@ascherbaum @shane_kerr AFAIK it is even best practice to flush the handlers at the end of each role.

ascherbaum,
@ascherbaum@mastodon.social avatar

@nebucatnetzer @shane_kerr I think (but I'm not sure right now) it even flushes handlers at the end of each role. The meta command allows to flush handlers earlier.

shane_kerr,
@shane_kerr@fosstodon.org avatar

@ascherbaum But that's about when the handler is invoked, right? The definition of the handler will still be far below the task that triggers it, won't it?

When reading a playbook I can follow the declarations, but it is far below then I have to save my position in the file, search for the handler, read it, then move back.

It's like using end notes instead of foot notes, requiring a lot more mental energy.

ascherbaum,
@ascherbaum@mastodon.social avatar

@shane_kerr Handlers are not immediate actions, and a Playbook can consume plenty of handlers (although that raised the question why the Playbook is so long and complex).

The fact that you have so many tasks before you reach the handlers might be worth splitting into more roles, and add them as dependencies.

shane_kerr,
@shane_kerr@fosstodon.org avatar

@ascherbaum Well I basically have a playbook that sets up everything on a metal server in a cluster. So installing packages, configuring email, creating swap, changing from systemd timesync to ntpd and so on. It's a lot of simple things. I guess that I can split it up, but have never had any reason to... until now, and it feels a bit arbitrary. 🤔

ascherbaum,
@ascherbaum@mastodon.social avatar

@shane_kerr simple but many lines of code don't go well together ;-)

From your description that should be at least 5 different roles, possibly more.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • Ansible
  • kavyap
  • thenastyranch
  • ethstaker
  • DreamBathrooms
  • osvaldo12
  • magazineikmin
  • tacticalgear
  • Youngstown
  • everett
  • mdbf
  • slotface
  • ngwrru68w68
  • rosin
  • Durango
  • JUstTest
  • InstantRegret
  • GTA5RPClips
  • tester
  • cubers
  • cisconetworking
  • normalnudes
  • khanakhh
  • modclub
  • anitta
  • Leos
  • megavids
  • provamag3
  • lostlight
  • All magazines