In some ansible roles (e.g. roles/my-role/) I've got quite some big default variables files (defaults/main.yml). I'd like to split the main.yml into several smaller files. Is it possible to do that?
I've tried creating the files defaults/1.yml and defaults/2.yml, but they aren't loaded by ansible.
The feature I'm describing below has been available since Ansible 2.6, but got a bugfix in v2.6.2 and another (minor) one in v2.7.
To see a solution for older versions, see Paul's answer.
defaults/main/Instead of creating
defaults/main.yml, create a directory —defaults/main/— and place all YAML files in there.defaults/main.yml→defaults/main/*.ymlAnsible will load any
*.ymlfile inside that directory, so you can name your files likeroles/my-role/defaults/main/{1,2}.yml.Furthermore, it's even possible to create sub-directories like
roles/my-role/defaults/main/subdir_1/foo.yml.Note, the old file —
defaults/main.yml— must not exist. See this Github comment.vars/main/By the way, the above solution also works for
vars/:vars/main.yml→vars/main/*.ymlfurther details
The feature has been introduced in v2.6 — git commit, Pull Request, main Github issue.
There have been two bugfixes: