Skip to content

Commit

Permalink
Add configmap jinja templates, fixes #66 (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
pabrahamsson authored and tylerauerbeck committed Nov 8, 2019
1 parent 65ff835 commit e500b16
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
51 changes: 51 additions & 0 deletions configmaps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# ConfigMaps

## configmap-env-vars.j2
You can use this to create a configmap with key value pairs. This jinja template will require a dict of the following name and format:
```yaml
configmap_env_vars:
key1: config1
key2: config2
key3: config3
```
Let's generate a configmap from the above:
`ansible -i <inventory> all -m template -a "src=configmap-env-vars.j2 dest=/tmp/configmap.yml" -e name=configmap-env-vars -e @/path/to/my/configmap_env_vars`
The generated configmap now looks like
```yaml
---
apiVersion: v1
kind: ConfigMap
metadata:
name: configmap-env-vars
data:
key3: config3
key2: config2
key1: config1
```

## configmap-files.j2
You can use this to create a configmap with multiple keys/files. This jinja template will require a dict of the following name and format:
```yaml
configmap_files:
file1.yml: |-
# This is a comment in 'file1.yml'
property1: blue
file2.yml: |-
property2: yellow
```
Let's generate a configmap from the above:
`ansible -i <inventory> all -m template -a "src=configmap-files.j2 dest=/tmp/configmap.yml" -e name=configmap-files -e @/path/to/my/configmap_files`
The generated configmap now looks like
```yaml
---
apiVersion: v1
kind: ConfigMap
metadata:
name: configmap-files
data:
file1.yml: |
# This is a comment in 'file1.yml'
property1: blue
file2.yml: |
property2: yellow
```
8 changes: 8 additions & 0 deletions configmaps/configmap-env-vars.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ name }}
data:
{% for key, value in configmap_env_vars.items() %}
{{ key }}: {{ value }}
{% endfor %}
11 changes: 11 additions & 0 deletions configmaps/configmap-files.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ name }}
data:
{% for filename, content in configmap_files.items() %}
{{ filename }}: |
{% for line in content.split('\n') %}
{{ line }}
{% endfor %}
{% endfor %}

0 comments on commit e500b16

Please sign in to comment.