Add Host to Group dynamically (or better: design question regarding a hacky solution)

Hi everyone,

I have a playbook that installs a web application on multiple hosts (one host per customer).

The following variable hierarchy would be perfect for my environment:

  • common.yml

  • $environment

  • $environment-$version.yml (because environment configuration can change with each new version)

  • fqdn.yml

In my playbook I have solved this via host_vars, group_vars and include_vars:

./group_vars
./group_vars/devel.yml

./group_vars/test.yml

./group_vars/production.yml

./host_vars

./host_vars/customer1.yml

./host_vars/customer2.yml

./host_vars/customer3.yml

- fail:
    msg: "app_version is not defined (application not yet deployed?)."
  when: app_version is not defined

- name: Include common vars
  include_vars:
    file: "common.yml"

- name: Include system type specific vars
  include_vars:
    file: "{{ app_version }}/{{ app_environment }}.yml"