使用yaml的分层配置
himl的Python项目详细描述
HIML
在python中使用yaml的分层配置。
最新版本为:0.2.1
说明
一个python模块,允许您使用yaml语法合并分层配置文件。它提供深度合并、变量插值和秘密管理器的秘密检索。
如果您希望以避免重复的方式构建层次结构,则这是理想的选择。您可以使用层次结构(如environment/project/cluster/app)定义配置的结构。你想在这个层次结构中使用什么层取决于你。该工具将从根(默认值为)开始读取所有yaml文件,一直到叶(最具体的值为,优先)。
这个想法来自木偶的神像。
目录
Installation
Using ^{}
^{pr 1}$
From Source
^{pr 2}$Examples
Using the python module
This will merge simple/default.yaml with simple/production/env.yaml
^{pr 3}$The above example will merge ^{
The example also showcases deep merging of lists and maps.
^{
^{
Result:
^{pr 7}$Using the cli
A cli tool called ^{
Based on the configuration tree from the examples/complex文件夹,上述命令的输出如下:
cluster:
description: 'This is cluster: cluster2. It is using c3.2xlarge instance type.'
name: cluster2
node_type: c3.2xlarge
region:
location: us-east-1
env: dev
“示例”文件夹的外观如下:
$ tree examples/complex
examples/complex
├── default.yaml
├── env=dev
│ ├── env.yaml
│ ├── region=us-east-1
│ │ ├── cluster=cluster1
│ │ │ └── cluster.yaml
│ │ ├── cluster=cluster2
│ │ │ └── cluster.yaml
│ │ └── region.yaml
│ └── region=us-west-2
│ ├── cluster=cluster1
│ │ └── cluster.yaml
│ └── region.yaml
└── env=prod
├── env.yaml
└── region=eu-west-2
├── cluster=ireland1
│ └── cluster.yaml
└── region.yaml
Features
Interpolation
In order to avoid repetition, we wanted to make it possible to define a value once and reuse it in other parts of the yaml config. Unlike yaml anchors, these interpolations work across multiple files.
Interpolating simple values
^{
^{
Interpolating whole ^{}
^{pr 14}$
Deep merge
It's possible to have the same key (eg. a dict/list) in multiple files and combine them using a deep merge. See an example here。
Secrets retrieval
AWS SSM
passphrase:"{{ssm.path(/key/coming/from/aws/secrets/store/manager).aws_profile(myprofile)}}"
Vault
尚未实施。
Merge with Terraform remote state
### Terraform remote states ###remote_states:-name:cluster_compositiontype:terraformaws_profile:"my_aws_profile"s3_bucket:"my_terraform_bucket"s3_key:"mycluster.tfstate"endpoint:"{{outputs.cluster_composition.output.value.redis_endpoint}}"