Run custom code before first task in playbook

Hi!

I use json facts caching and sometimes this files expires (last modified time > than configured fact_caching_timeout).
This is a rare problem, but if it arises - I have non-obvious errors in stdout after running my playbook (like “ansible_fqdn is not defined in host_vars”, etc).

My idea: run some custom assertion code, that should check all cache files for expiration and stop further playbook run if there are some expired cache files with a good understandable message.
How can I embed my custom check code in playbook? Maybe I should write some sort of ansible plugin?

Thanks.

I do something similar, I just use the assert module to check a fact that I know should be set to a predefined value.

`

  • name: “linux : global assertions”
    assert:
    that:
  • “group_ld_all_000_global_defaults == ‘loaded’”
    fail_msg: ‘environment issue, please double check, this is most likely a issue with fact cache expiring’
    `