Skip to main content
Version: 1.3

Selecting multiple configs from a Config Group

Β Example (Click Here)

Problem​

In some scenarios, one may need to select multiple configs from the same Config Group.

Solution​

Use a list of config names as the value of the config group in the Defaults List or in the command line.

Example​

In this example, we configure a server. The server can host multiple websites at the same time.

Config directory
β”œβ”€β”€ config.yaml
└── server
β”œβ”€β”€ apache.yaml
└── site
β”œβ”€β”€ amazon.yaml
β”œβ”€β”€ fb.yaml
└── google.yaml
config.yaml
defaults:
- server/apache





server/apache.yaml
defaults:
- site:
- fb
- google

host: localhost
port: 443
server/site/amazon.yaml
amazon:
domain: amazon.com
server/site/fb.yaml
fb:
domain: facebook.com
server/site/google.yaml
google:
domain: google.com

Output:

$ python my_app.py
server:
site:
fb:
domain: facebook.com
google:
domain: google.com
host: localhost
port: 443

Override the selected sites from the command line by passing a list. e.g:

$ python my_app.py 'server/site=[google,amazon]'
server:
site:
google:
domain: google.com
amazon:
domain: amazon.com
host: localhost
port: 443

Overriding packages​

You can relocate the package of all the configs in the list. e.g:

server/apache.yaml
defaults:
- site@https:
- fb
- google


$ python my_app.py
server:
https:
fb:
domain: facebook.com
google:
domain: google.com

When overriding the selected configs of config groups with overridden packages you need to use the package. e.g:

$ python my_app.py server/[email protected]=amazon
server:
https:
amazon:
domain: amazon.com
host: localhost
port: 443

Implementation considerations​

A nested list in the Defaults List is interpreted as a list of non-overridable configs:

server/apache.yaml
defaults:
- site:
- fb
- google
Equivalent to
defaults:
- site/fb
- site/google

All default package for all the configs in server/site is server.site. This example uses an explicit nesting level inside each of the website configs to prevent them stepping over one another:

server/site/amazon.yaml
amazon:
...