Force a role to be run on every host in every inventory file without explicitly calling the role from a playbook

Hi,

I’m wondering if there is an easy way to enforce that a certain role would be run for every host in every inventory file, without explicitly having to call the role from a playbook and without needing to run a command from the CLI to do it.

My thinking is that I’d have a security role, that hardens a host and that if anyone else came along and created a new inventory and a new playbook and didn’t include the security role, even when they ran a playbook against their new host, the security role would be run anyway.

It may not be the best idea, but I am just wondering if it is possible, perhaps by doing something in the ansible.cfg file, (nothing is jumping out at me at the moment).

Any feedback would be much appreciated.

Thanks,
Graeme

Hello Graeme,
One way is to make playbook which include role and run that playbook everyday or some days using cron job.

so playbook look like:
run.yml

hosts: all
roles:

  • security role

then cron job will be:

12 10 00 12 ansible-playbook run.yml

or other way is to write bash script for it.