Hostvars or role vars?

So i need to pick your brain about something.
I have automated alot of tasks on a few servers regarding applications running on them. I have generated alot of var files for each application, license etc.

Is it best to host all those variable files in host vars since they are spesific for each host or in the vars/ directory under the role? Some of the var lines can be used in other playbooks also.

I would refer you to the docs for var precendence. By understanding the precendence , you the user, can make a better determination where your vars should go:
Using Variables — Ansible Community Documentation. I typically go with the lowest precendece that can cast the widest net for my particular use case. Sometimes that means the vars are in a role, and sometimes that means i’m using specific host_vars. Personally, I do try to minimize my use of individual host_var files, but that doesn’t mean I don’t use them.

1 Like