service: Better organize vars
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
---
|
||||
_service_volume_mounts: "{{ service_container_mounts | selectattr('type', '==', 'volume') }}"
|
||||
_service_template_mounts: "{{ service_container_mounts | selectattr('type', '==', 'template') }}"
|
||||
_service_host_directory: "/srv/{{ service_name }}"
|
||||
|
||||
_service_container_volume_mounts: >-
|
||||
{{
|
||||
_service_volume_mounts |
|
||||
zip(
|
||||
_service_volume_mounts |
|
||||
map(attribute='source') |
|
||||
map('regex_replace', '^', service_name ~ '-') |
|
||||
map('community.general.dict_kv', 'source')
|
||||
) |
|
||||
map('combine')
|
||||
}}
|
||||
_service_container_bind_mounts: "{{ service_container_mounts | selectattr('type', '==', 'bind') }}"
|
||||
_service_container_template_mounts: >-
|
||||
{{
|
||||
([{'readonly': true}] * _service_template_mounts | length) |
|
||||
zip(
|
||||
_service_template_mounts,
|
||||
_service_template_mounts |
|
||||
map(attribute='source') |
|
||||
map('regex_replace', '\.j2$', '') |
|
||||
map('regex_replace', '^', _service_host_directory ~ '/mounts/') |
|
||||
map('community.general.dict_kv', 'source'),
|
||||
([{'type': 'bind'}] * _service_template_mounts | length)
|
||||
) |
|
||||
map('combine')
|
||||
}}
|
||||
|
||||
_service_container_mounts: >-
|
||||
{{
|
||||
_service_container_volume_mounts +
|
||||
_service_container_bind_mounts +
|
||||
_service_container_template_mounts
|
||||
}}
|
||||
|
||||
_service_setup_database: "{{ service_database_type != 'none' }}"
|
||||
_service_database_name: "{{ service_name }}-{{ service_database_type }}"
|
||||
|
||||
_service_container_networks: "{{ [service_name] + service_container_additional_networks }}"
|
||||
|
||||
_service_container_secrets: >-
|
||||
{{
|
||||
service_container_secrets
|
||||
| map(attribute='name')
|
||||
| map('community.general.dict_kv', 'target')
|
||||
| zip(
|
||||
service_container_secrets,
|
||||
service_container_secrets
|
||||
| map(attribute='name')
|
||||
| map('regex_replace', '^', service_name ~ '-')
|
||||
| map('community.general.dict_kv', 'name')
|
||||
)
|
||||
| map('combine')
|
||||
+ (
|
||||
[{
|
||||
'name': _service_database_name,
|
||||
'type': service_database_secret_type,
|
||||
'target': service_database_secret_target
|
||||
}] if _service_setup_database else []
|
||||
)
|
||||
}}
|
||||
|
||||
_service_additional_containers: >-
|
||||
{{
|
||||
service_additional_containers
|
||||
| zip(
|
||||
service_additional_containers
|
||||
| map(attribute='name')
|
||||
| map('regex_replace', '^', service_name ~ '-')
|
||||
| map('community.general.dict_kv', 'name')
|
||||
)
|
||||
| map('combine')
|
||||
}}
|
||||
|
||||
_service_container_requires: >-
|
||||
{{
|
||||
service_requires
|
||||
+ ([_service_database_name + '.service'] if _service_setup_database else [])
|
||||
+ ([service_name + '-redis.service'] if service_redis else [])
|
||||
}}
|
||||
_service_container_wants: >-
|
||||
{{
|
||||
service_wants
|
||||
+ ([service_name + '-socat.socket'] if service_domains | length > 0 else [])
|
||||
+ _service_additional_containers
|
||||
| map(attribute='name')
|
||||
| map('regex_replace', '$', '.service')
|
||||
}}
|
||||
|
||||
_service_replacement_host_header:
|
||||
Host: "{{ service_name }}:{{ service_container_http_port }}"
|
||||
_service_proxy_headers: "{{ _service_replacement_host_header if not service_proxy_pass_host_header else {} }}"
|
||||
54
roles/service/vars/main/additional.yaml
Normal file
54
roles/service/vars/main/additional.yaml
Normal file
@@ -0,0 +1,54 @@
|
||||
---
|
||||
_service_additional_containers: >-
|
||||
{{
|
||||
service_additional_containers
|
||||
| zip(
|
||||
service_additional_containers
|
||||
| map(attribute='name')
|
||||
| map('regex_replace', '^', service_name ~ '-')
|
||||
| map('community.general.dict_kv', 'name')
|
||||
)
|
||||
| map('combine')
|
||||
}}
|
||||
|
||||
|
||||
_service_additional_volume_mounts: "{{ _service_additional_container.mounts | selectattr('type', '==', 'volume') }}"
|
||||
_service_additional_template_mounts: "{{ _service_additional_container.mounts | selectattr('type', '==', 'template') }}"
|
||||
_service_additional_host_directory: "/srv/{{ service_name }}"
|
||||
|
||||
_service_additional_container_volume_mounts: >-
|
||||
{{
|
||||
_service_additional_volume_mounts |
|
||||
zip(
|
||||
_service_additional_volume_mounts |
|
||||
map(attribute='source') |
|
||||
map('regex_replace', '^', service_name ~ '-') |
|
||||
map('community.general.dict_kv', 'source')
|
||||
) |
|
||||
map('combine')
|
||||
}}
|
||||
_service_additional_container_bind_mounts: "{{ _service_additional_container.mounts | selectattr('type', '==', 'bind') }}"
|
||||
_service_additional_container_template_mounts: >-
|
||||
{{
|
||||
([{'readonly': true}] * _service_additional_template_mounts | length) |
|
||||
zip(
|
||||
_service_additional_template_mounts,
|
||||
_service_additional_template_mounts |
|
||||
map(attribute='source') |
|
||||
map('regex_replace', '\.j2$', '') |
|
||||
map('regex_replace', '^', _service_host_directory ~ '/mounts/') |
|
||||
map('community.general.dict_kv', 'source'),
|
||||
([{'type': 'bind'}] * _service_additional_template_mounts | length)
|
||||
) |
|
||||
map('combine')
|
||||
}}
|
||||
|
||||
_service_additional_container_mounts: >-
|
||||
{{
|
||||
_service_additional_container_volume_mounts +
|
||||
_service_additional_container_bind_mounts +
|
||||
_service_additional_container_template_mounts
|
||||
if _service_additional_container.mounts is defined
|
||||
else
|
||||
_service_container_mounts
|
||||
}}
|
||||
24
roles/service/vars/main/general.yaml
Normal file
24
roles/service/vars/main/general.yaml
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
_service_setup_database: "{{ service_database_type != 'none' }}"
|
||||
_service_database_name: "{{ service_name }}-{{ service_database_type }}"
|
||||
|
||||
_service_container_networks: "{{ [service_name] + service_container_additional_networks }}"
|
||||
|
||||
_service_container_requires: >-
|
||||
{{
|
||||
service_requires
|
||||
+ ([_service_database_name + '.service'] if _service_setup_database else [])
|
||||
+ ([service_name + '-redis.service'] if service_redis else [])
|
||||
}}
|
||||
_service_container_wants: >-
|
||||
{{
|
||||
service_wants
|
||||
+ ([service_name + '-socat.socket'] if service_domains | length > 0 else [])
|
||||
+ _service_additional_containers
|
||||
| map(attribute='name')
|
||||
| map('regex_replace', '$', '.service')
|
||||
}}
|
||||
|
||||
_service_replacement_host_header:
|
||||
Host: "{{ service_name }}:{{ service_container_http_port }}"
|
||||
_service_proxy_headers: "{{ _service_replacement_host_header if not service_proxy_pass_host_header else {} }}"
|
||||
38
roles/service/vars/main/mounts.yaml
Normal file
38
roles/service/vars/main/mounts.yaml
Normal file
@@ -0,0 +1,38 @@
|
||||
---
|
||||
_service_volume_mounts: "{{ service_container_mounts | selectattr('type', '==', 'volume') }}"
|
||||
_service_template_mounts: "{{ service_container_mounts | selectattr('type', '==', 'template') }}"
|
||||
_service_host_directory: "/srv/{{ service_name }}"
|
||||
|
||||
_service_container_volume_mounts: >-
|
||||
{{
|
||||
_service_volume_mounts |
|
||||
zip(
|
||||
_service_volume_mounts |
|
||||
map(attribute='source') |
|
||||
map('regex_replace', '^', service_name ~ '-') |
|
||||
map('community.general.dict_kv', 'source')
|
||||
) |
|
||||
map('combine')
|
||||
}}
|
||||
_service_container_bind_mounts: "{{ service_container_mounts | selectattr('type', '==', 'bind') }}"
|
||||
_service_container_template_mounts: >-
|
||||
{{
|
||||
([{'readonly': true}] * _service_template_mounts | length) |
|
||||
zip(
|
||||
_service_template_mounts,
|
||||
_service_template_mounts |
|
||||
map(attribute='source') |
|
||||
map('regex_replace', '\.j2$', '') |
|
||||
map('regex_replace', '^', _service_host_directory ~ '/mounts/') |
|
||||
map('community.general.dict_kv', 'source'),
|
||||
([{'type': 'bind'}] * _service_template_mounts | length)
|
||||
) |
|
||||
map('combine')
|
||||
}}
|
||||
|
||||
_service_container_mounts: >-
|
||||
{{
|
||||
_service_container_volume_mounts +
|
||||
_service_container_bind_mounts +
|
||||
_service_container_template_mounts
|
||||
}}
|
||||
22
roles/service/vars/main/secrets.yaml
Normal file
22
roles/service/vars/main/secrets.yaml
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
_service_container_secrets: >-
|
||||
{{
|
||||
service_container_secrets
|
||||
| map(attribute='name')
|
||||
| map('community.general.dict_kv', 'target')
|
||||
| zip(
|
||||
service_container_secrets,
|
||||
service_container_secrets
|
||||
| map(attribute='name')
|
||||
| map('regex_replace', '^', service_name ~ '-')
|
||||
| map('community.general.dict_kv', 'name')
|
||||
)
|
||||
| map('combine')
|
||||
+ (
|
||||
[{
|
||||
'name': _service_database_name,
|
||||
'type': service_database_secret_type,
|
||||
'target': service_database_secret_target
|
||||
}] if _service_setup_database else []
|
||||
)
|
||||
}}
|
||||
Reference in New Issue
Block a user