Vendor Galaxy Roles and Collections
This commit is contained in:
parent
c1e1897cda
commit
2aed20393f
7 changed files with 387444 additions and 2 deletions
19
ansible_collections/debops/debops/roles/prosody/COPYRIGHT
Normal file
19
ansible_collections/debops/debops/roles/prosody/COPYRIGHT
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
debops.prosody - Manage Prosody XMPP server with Ansible
|
||||
|
||||
Copyright (C) 2018 Norbert Summer <git@o-g.at>
|
||||
Copyright (C) 2018 DebOps <https://debops.org/>
|
||||
SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
This Ansible role is part of DebOps.
|
||||
|
||||
DebOps is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 3, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
DebOps is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DebOps. If not, see https://www.gnu.org/licenses/.
|
||||
|
|
@ -0,0 +1,379 @@
|
|||
---
|
||||
# .. vim: foldmarker=[[[,]]]:foldmethod=marker
|
||||
|
||||
# .. Copyright (C) 2018 Norbert Summer <git@o-g.at>
|
||||
# .. Copyright (C) 2018 DebOps <https://debops.org/>
|
||||
# .. SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# .. _prosody__ref_defaults:
|
||||
|
||||
# debops.prosody default variables [[[
|
||||
# ====================================
|
||||
|
||||
# .. contents:: Sections
|
||||
# :local:
|
||||
#
|
||||
# .. include:: ../../../../includes/global.rst
|
||||
|
||||
|
||||
# Packages and installation [[[
|
||||
# -----------------------------
|
||||
|
||||
# .. envvar:: prosody__base_packages [[[
|
||||
#
|
||||
# List of base packages to install.
|
||||
prosody__base_packages:
|
||||
- 'prosody'
|
||||
- 'lua-zlib'
|
||||
- 'lua-sec'
|
||||
- 'prosody-modules' # for ldap auth
|
||||
- '{{ "lua-event" if prosody__use_libevent | bool else [] }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__packages [[[
|
||||
#
|
||||
# List of additional APT packages to install with Prosody.
|
||||
prosody__packages: []
|
||||
# ]]]
|
||||
# ]]]
|
||||
# PKI [[[
|
||||
# -------
|
||||
|
||||
# .. envvar:: prosody__pki [[[
|
||||
#
|
||||
# Enable or disable support for PKI/SSL/TLS in prosody.
|
||||
# Defaults to ``True`` if :ref:`debops.pki` is enabled on the remote host.
|
||||
prosody__pki: '{{ ansible_local.pki.enabled | d() | bool }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__pki_realm_path [[[
|
||||
#
|
||||
# Directory path where PKI realm live.
|
||||
prosody__pki_realm_path: '{{ ansible_local.pki.path | d("/etc/pki/realms") }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__pki_realm [[[
|
||||
#
|
||||
# Default PKI realm to use.
|
||||
prosody__pki_realm: '{{ ansible_local.pki.realm | d("domain") }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__pki_crt_filename [[[
|
||||
#
|
||||
# Default CRT file name to use.
|
||||
prosody__pki_crt_filename: '{{ ansible_local.pki.crt | d("default.crt") }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__pki_key_filename [[[
|
||||
#
|
||||
# Default private key file name to use.
|
||||
prosody__pki_key_filename: '{{ ansible_local.pki.key | d("default.key") }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__pki_hook_name [[[
|
||||
#
|
||||
# Name of the hook script which will be stored in hook directory.
|
||||
prosody__pki_hook_name: 'prosody'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__pki_hook_path [[[
|
||||
#
|
||||
# Directory with PKI hooks.
|
||||
prosody__pki_hook_path: '{{ ansible_local.pki.hooks | d("/etc/pki/hooks") }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__pki_hook_action [[[
|
||||
#
|
||||
# Specify how changes in PKI should affect prosody, either 'reload' or 'restart'.
|
||||
prosody__pki_hook_action: 'reload'
|
||||
# ]]]
|
||||
# ]]]
|
||||
# Prosody Configuration [[[
|
||||
# -------------------------
|
||||
|
||||
# .. envvar:: prosody__deploy_state [[[
|
||||
#
|
||||
# Set to `absent` to disable and uninstall this role
|
||||
prosody__deploy_state: "present"
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__domain [[[
|
||||
#
|
||||
# The hosts's DNS domain name used in the Prosody configuration.
|
||||
prosody__domain: '{{ ansible_domain }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__admins [[[
|
||||
#
|
||||
# List of admin jabber accounts of this prosody instance
|
||||
prosody__admins: []
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__use_libevent [[[
|
||||
#
|
||||
# Set this to true to enable the libevent backend
|
||||
# @see https://prosody.im/doc/libevent
|
||||
prosody__use_libevent: false
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__modules_default [[[
|
||||
#
|
||||
# Modules that are loaded by default
|
||||
# @see https://prosody.im/doc/configure
|
||||
prosody__modules_default:
|
||||
- "roster"
|
||||
- "saslauth"
|
||||
- "tls"
|
||||
- "dialback"
|
||||
- "disco"
|
||||
- "private"
|
||||
- "vcard"
|
||||
- "privacy" #@TODO check version < 0.10
|
||||
- "version"
|
||||
- "uptime"
|
||||
- "time"
|
||||
- "ping"
|
||||
- "pep"
|
||||
- "admin_adhoc"
|
||||
- "posix"
|
||||
- "groups"
|
||||
- "carbons"
|
||||
- "mam"
|
||||
- "blocking"
|
||||
- "smacks"
|
||||
#- "s2s_auth_dane"
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__modules [[[
|
||||
#
|
||||
# Modules that should be enabled
|
||||
prosody__modules: '{{ prosody__modules_default }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__authentication [[[
|
||||
#
|
||||
# Providers:
|
||||
# - internal_plain
|
||||
# - internal_hashed
|
||||
# - cyrus
|
||||
# - anonymous
|
||||
# - ldap2 (TODO)
|
||||
#
|
||||
# https://prosody.im/doc/authentication
|
||||
prosody__authentication: 'internal_plain'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__insecure_domains [[[
|
||||
#
|
||||
# List of insecure domains. As example `gmail.com`
|
||||
# https://prosody.im/doc/s2s
|
||||
prosody__insecure_domains: []
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__allow_registration [[[
|
||||
#
|
||||
# Allow new registrations
|
||||
prosody__allow_registration: False
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__config_ldap [[[
|
||||
#
|
||||
# LDAP config, this is used when `prosody__authentication` is ldap2.
|
||||
# https://modules.prosody.im/mod_auth_ldap2.html
|
||||
prosody__config_ldap:
|
||||
ldap:
|
||||
hostname: 'ldap.{{ ansible_domain }}'
|
||||
user:
|
||||
basedn: 'ou=users,..@TODO'
|
||||
usernamefield: 'uid'
|
||||
bind_dn: 'uid=....,dc=...@TODO'
|
||||
bind_password: 'lookup..@TODO'
|
||||
use_tls: True
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__default_config_global [[[
|
||||
#
|
||||
# Main prosody configuration, default values
|
||||
# @see https://prosody.im/doc/configure
|
||||
prosody__default_config_global:
|
||||
admins: '{{ prosody__admins }}'
|
||||
modules_enabled: '{{ prosody__modules }}'
|
||||
allow_registration: '{{ prosody__allow_registration }}'
|
||||
daemonize: True
|
||||
pidfile: "/var/run/prosody/prosody.pid"
|
||||
use_libevent: '{{ prosody__use_libevent }}'
|
||||
c2s_require_encryption: True
|
||||
s2s_require_encryption: True
|
||||
s2s_secure_auth: True
|
||||
s2s_insecure_domains: '{{ prosody__insecure_domains }}'
|
||||
authentication: '{{ prosody__authentication }}'
|
||||
log:
|
||||
info: "/var/log/prosody/prosody.log"
|
||||
error: "/var/log/prosody/prosody.err"
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__config_http_server [[[
|
||||
#
|
||||
# HTTP server specific settings.
|
||||
# More infos at https://prosody.im/doc/http
|
||||
prosody__config_http_server:
|
||||
http_port:
|
||||
- 5280
|
||||
http_interface:
|
||||
- '*'
|
||||
https_port:
|
||||
- 5281
|
||||
https_interface:
|
||||
- '*'
|
||||
https_ssl:
|
||||
certificate: '{{ prosody__pki_realm_path + "/" + prosody__pki_realm + "/" + prosody__pki_crt_filename }}'
|
||||
key: '{{ prosody__pki_realm_path + "/" + prosody__pki_realm + "/" + prosody__pki_key_filename }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__config_global [[[
|
||||
#
|
||||
# Mapping for global configs which will be managed on all hosts in the Ansible
|
||||
# inventory.
|
||||
prosody__config_global: {}
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__group_config_global [[[
|
||||
#
|
||||
# Mapping for global configs which will be managed on specific groups in the Ansible
|
||||
# inventory.
|
||||
prosody__group_config_global: {}
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__host_config_global [[[
|
||||
#
|
||||
# Mapping for global configs which will be managed on specific hosts in the Ansible
|
||||
# inventory.
|
||||
prosody__host_config_global: {}
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__combined_config_global [[[
|
||||
#
|
||||
# Mapping which combines all of the global config variables and is used
|
||||
# in the configuration template.
|
||||
prosody__combined_config_global: '{{ prosody__default_config_global | combine(prosody__config_http_server,
|
||||
prosody__config_ldap if prosody__authentication == "ldap2" else {},
|
||||
prosody__config_global,
|
||||
prosody__group_config_global,
|
||||
prosody__host_config_global) }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__config_virtual_hosts [[[
|
||||
#
|
||||
# List of virtual hosts
|
||||
prosody__config_virtual_hosts:
|
||||
- name: '{{ ansible_domain }}'
|
||||
enabled: false
|
||||
pki_realm: 'domain'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__http_upload [[[
|
||||
#
|
||||
# http_upload enables upload via http(s) for clients to share files
|
||||
# https://modules.prosody.im/mod_http_upload.html
|
||||
# XEP-0363
|
||||
prosody__http_upload: True
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__muc [[[
|
||||
#
|
||||
# muc (multi user channel) enables group channel function.
|
||||
# https://prosody.im/doc/modules/mod_muc
|
||||
# XEP-0045
|
||||
prosody__muc: True
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__config_http_upload [[[
|
||||
#
|
||||
# http_upload config is for client upload via http(s) to share files
|
||||
# https://modules.prosody.im/mod_http_upload.html
|
||||
# XEP-0363
|
||||
prosody__config_http_upload:
|
||||
- domain: 'upload.{{ prosody__domain }}'
|
||||
params: '"http_upload"'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__config_muc [[[
|
||||
#
|
||||
# muc (multi user channel) config for group channel function.
|
||||
# https://prosody.im/doc/modules/mod_muc
|
||||
# XEP-0045
|
||||
prosody__config_muc:
|
||||
- domain: 'conference.{{ prosody__domain }}'
|
||||
params: '"muc"'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__default_config_components [[[
|
||||
#
|
||||
# List of default components
|
||||
prosody__default_config_components: '{{ (prosody__config_http_upload if prosody__http_upload | bool else [])
|
||||
+ (prosody__config_muc if prosody__muc | bool else []) }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__config_components [[[
|
||||
#
|
||||
# List of components which will be managed on all hosts in the Ansible
|
||||
# inventory.
|
||||
prosody__config_components: []
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__group_config_components [[[
|
||||
#
|
||||
# List of components which will be managed on specific groups in the Ansible
|
||||
# inventory.
|
||||
prosody__group_config_components: []
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__host_config_components [[[
|
||||
#
|
||||
# List of components which will be managed on specific hosts in the Ansible
|
||||
# inventory.
|
||||
prosody__host_config_components: []
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__combined_config_components [[[
|
||||
#
|
||||
# List which combines all of the global config variables and is used
|
||||
# in the configuration template.
|
||||
prosody__combined_config_components: '{{ prosody__default_config_components
|
||||
+ prosody__config_components
|
||||
+ prosody__group_config_components
|
||||
+ prosody__host_config_components }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: prosody__ferm__dependent_rules [[[
|
||||
#
|
||||
# Configuration for :command:`iptables` firewall managed by :program:`ferm`.
|
||||
prosody__ferm__dependent_rules:
|
||||
|
||||
- type: 'accept'
|
||||
dport: [ '5222' ]
|
||||
accept_any: True
|
||||
weight: '40'
|
||||
by_role: 'prosody'
|
||||
name: 'prosody-xmpp-client'
|
||||
multiport: True
|
||||
rule_state: '{{ prosody__deploy_state }}'
|
||||
- type: 'accept'
|
||||
dport: [ '5269' ]
|
||||
accept_any: True
|
||||
weight: '40'
|
||||
by_role: 'prosody'
|
||||
name: 'prosody-xmpp-server'
|
||||
multiport: True
|
||||
rule_state: '{{ prosody__deploy_state }}'
|
||||
- type: 'accept'
|
||||
dport: [ '5280', '5281' ]
|
||||
accept_any: True
|
||||
weight: '40'
|
||||
by_role: 'prosody'
|
||||
name: 'prosody-http'
|
||||
multiport: True
|
||||
rule_state: '{{ prosody__deploy_state }}'
|
||||
# ]]]
|
||||
# ]]]
|
||||
# ]]]
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
# Copyright (C) 2018 Norbert Summer <git@o-g.at>
|
||||
# Copyright (C) 2018 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# Ensure that custom Ansible plugins and modules included in the main DebOps
|
||||
# collection are available to roles in other collections.
|
||||
collections: [ 'debops.debops' ]
|
||||
|
||||
dependencies: []
|
||||
|
||||
galaxy_info:
|
||||
|
||||
company: 'DebOps'
|
||||
author: 'Norbert Summer'
|
||||
description: 'Lightweight Jabber/XMPP server'
|
||||
license: 'GPL-3.0-only'
|
||||
min_ansible_version: '2.2.0'
|
||||
|
||||
platforms:
|
||||
|
||||
- name: Debian
|
||||
versions:
|
||||
- stretch
|
||||
|
||||
- name: Ubuntu
|
||||
versions:
|
||||
- xenial
|
||||
- artful
|
||||
|
||||
galaxy_tags:
|
||||
- prosody
|
||||
- jabber
|
||||
- xmpp
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
---
|
||||
# Copyright (C) 2018 Norbert Summer <git@o-g.at>
|
||||
# Copyright (C) 2018 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
- name: Import DebOps global handlers
|
||||
ansible.builtin.import_role:
|
||||
name: 'global_handlers'
|
||||
|
||||
- name: Install required packages
|
||||
ansible.builtin.package:
|
||||
name: '{{ q("flattened", (prosody__base_packages
|
||||
+ prosody__packages)) }}'
|
||||
state: 'present'
|
||||
register: prosody__register_packages
|
||||
until: prosody__register_packages is succeeded
|
||||
|
||||
- name: Generate Prosody configuration
|
||||
ansible.builtin.template:
|
||||
src: 'etc/prosody/prosody.cfg.lua.j2'
|
||||
dest: '/etc/prosody/prosody.cfg.lua'
|
||||
mode: '0640'
|
||||
notify: [ 'Restart prosody' ]
|
||||
|
||||
- name: Enable Services
|
||||
ansible.builtin.service:
|
||||
name: '{{ item }}'
|
||||
enabled: 'yes'
|
||||
state: 'started'
|
||||
with_items:
|
||||
- prosody
|
||||
|
||||
- name: Make sure that PKI hook directory exists
|
||||
ansible.builtin.file:
|
||||
path: '{{ prosody__pki_hook_path }}'
|
||||
state: 'directory'
|
||||
owner: 'root'
|
||||
group: 'root'
|
||||
mode: '0755'
|
||||
when: (prosody__pki | bool and prosody__deploy_state in ['present'])
|
||||
|
||||
- name: Manage PKI prosody hook
|
||||
ansible.builtin.template:
|
||||
src: 'etc/pki/hooks/prosody.j2'
|
||||
dest: '{{ prosody__pki_hook_path + "/" + prosody__pki_hook_name }}'
|
||||
owner: 'root'
|
||||
group: 'root'
|
||||
mode: '0755'
|
||||
when: (prosody__pki | bool and prosody__deploy_state in ['present'])
|
||||
|
||||
- name: Ensure the PKI prosody hook is absent
|
||||
ansible.builtin.file:
|
||||
path: '{{ prosody__pki_hook_path + "/" + prosody__pki_hook_name }}'
|
||||
state: 'absent'
|
||||
when: (prosody__deploy_state in ['absent'])
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright (C) 2018 Norbert Summer <git@o-g.at>
|
||||
# Copyright (C) 2018 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# {{ ansible_managed }}
|
||||
|
||||
# Reload or restart prosody on a certificate state change
|
||||
|
||||
set -o nounset -o pipefail -o errexit
|
||||
|
||||
prosody_config="/etc/prosody/prosody.cfg.lua"
|
||||
prosody_action="{{ prosody__pki_hook_action }}"
|
||||
|
||||
# Check if current PKI realm is used by the 'prosody' webserver
|
||||
certificate=$(grep -r "${PKI_SCRIPT_DEFAULT_CRT:-}" ${prosody_config} || true)
|
||||
|
||||
# Get list of current realm states
|
||||
read -r -a states <<< "$(echo "${PKI_SCRIPT_STATE:-}" | tr "," " ")"
|
||||
|
||||
if [ -n "${certificate}" ] && [[ ${states[*]} ]] ; then
|
||||
|
||||
for state in "${states[@]}" ; do
|
||||
|
||||
if [ "${state}" = "changed-certificate" ] || [ "${state}" = "changed-dhparam" ] ; then
|
||||
|
||||
# Check if current init is systemd
|
||||
if pidof systemd > /dev/null 2>&1 ; then
|
||||
|
||||
prosody_state="$(systemctl is-active prosody.service)"
|
||||
if [ "${prosody_state}" = "active" ] ; then
|
||||
if prosodyctl check > /dev/null 2>&1 ; then
|
||||
systemctl "${prosody_action}" prosody.service
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
break
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
fi
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
{# Copyright (C) 2018 Norbert Summer <git@o-g.at>
|
||||
# Copyright (C) 2018 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#}
|
||||
-- {{ ansible_managed }}
|
||||
{% import 'templates/import/debops__tpl_macros.j2' as debops__tpl_macros with context %}
|
||||
|
||||
{% macro lua_print(object, prefix='',depth=0) %}
|
||||
{% if object is mapping %}
|
||||
{% set prefix = prefix + ' ' %}
|
||||
{% if depth!=0 %}{{ "{\n" }}{% endif %}
|
||||
{% for _item_name, _value in object |dictsort %}
|
||||
{{ _item_name+' = '+lua_print(_value, prefix,depth+1)|indent(2,true) }}
|
||||
{% endfor %}
|
||||
{% if depth!=0 %}{{ '}' }}{% endif %}
|
||||
{% elif 'bool' == object|type_debug %}
|
||||
{% if object %}{{ 'true;'|indent(2,true) }}
|
||||
{% else %}{{ 'false;'|indent(2,true) }}{% endif %}
|
||||
{% elif object is string %}
|
||||
{{ '"' + object + '";' }}
|
||||
{% elif object is iterable %}
|
||||
{% if depth!=0 %}{{ "{\n" }}{% endif %}
|
||||
{% for _item in object %}
|
||||
{{ lua_print(_item, prefix,depth+1)|indent(2,true) }}
|
||||
{% endfor %}
|
||||
{% if depth!=0 %}{{ '}' }}{% endif %}
|
||||
{% elif object is number %}
|
||||
{{ '%d' | format(object)|indent(2,true) }}
|
||||
{% else %}
|
||||
error unknown type
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
{{ lua_print(prosody__combined_config_global,'',false) }}
|
||||
|
||||
|
||||
{% for item in prosody__config_virtual_hosts %}
|
||||
{% set prosody__tpl_pki_realm = item.pki_realm %}{#| d((debops__tpl_macros.get_realm_yaml_list(item.name, prosody__pki_realm) | from_yaml)[0]) %#}
|
||||
{% set prosody__tpl_pki_realm_path = prosody__pki_realm_path + "/" + prosody__tpl_pki_realm %}
|
||||
VirtualHost "{{ item.name }}"
|
||||
enabled = {{ item.enabled }}
|
||||
|
||||
ssl = {
|
||||
certificate = "{{ item.tls_crt | d(prosody__tpl_pki_realm_path + "/" + (item.pki_crt | d(prosody__pki_crt_filename))) }}";
|
||||
key = "{{ item.tls_key | d(prosody__tpl_pki_realm_path + "/" + (item.pki_key | d(prosody__pki_key_filename))) }}";
|
||||
}
|
||||
{{ item.raw | d("") }}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{% for _component in prosody__combined_config_components %}
|
||||
Component "{{ _component.domain }}" {{ _component.params }}
|
||||
{% endfor %}
|
||||
|
|
@ -0,0 +1,225 @@
|
|||
{# vim: foldmarker=[[[,]]]:foldmethod=marker
|
||||
# Commonly used set of macros in DebOps.
|
||||
# It can be imported in repositories as needed.
|
||||
# Changes to this file should go upstream: https://github.com/debops/debops-playbooks/blob/master/templates/debops__tpl_macros.j2
|
||||
#
|
||||
# Copyright [[[
|
||||
# =============
|
||||
#
|
||||
# Copyright (C) 2014-2017 Maciej Delmanowski <drybjed@drybjed.net>
|
||||
# Copyright (C) 2015-2017 Robin Schneider <ypid@riseup.net>
|
||||
# Copyright (C) 2014-2017 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#
|
||||
# This file is part of DebOps.
|
||||
#
|
||||
# DebOps is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License version 3, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# DebOps is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with DebOps. If not, see https://www.gnu.org/licenses/.
|
||||
#
|
||||
# ]]]
|
||||
#
|
||||
# Usage [[[
|
||||
# =========
|
||||
#
|
||||
# Copy the template file to `./templates/import/debops__tpl_macros.j2` of your
|
||||
# role and import it from there into various other templates or even use it
|
||||
# in templates which are called by {{ lookup("template", ...) }}.
|
||||
#
|
||||
# Make sure to retain the filename of this file so that automatic updates of
|
||||
# this file can be implemented.
|
||||
#
|
||||
# To use the macros in your own template, this file needs to be imported like so:
|
||||
#
|
||||
# {% import 'templates/import/debops__tpl_macros.j2' as debops__tpl_macros with context %}
|
||||
#
|
||||
# Then you can start using the macros like this:
|
||||
#
|
||||
# {{ debops__tpl_macros.indent(some_content, 4) }}
|
||||
#
|
||||
# ]]] #}
|
||||
|
||||
{% macro get_realm_yaml_list(domains, fallback_realm) %}{# [[[ #}
|
||||
{% set custom_realm_list = [] %}
|
||||
{% if domains and (ansible_local.pki.known_realms | d()) %}
|
||||
{% for domain in (get_yaml_list_for_elem(domains) | from_yaml) %}
|
||||
{% if domain in ansible_local.pki.known_realms %}
|
||||
{% set _ = custom_realm_list.append(domain) %}
|
||||
{% elif (domain.split('.')[1:] | join('.')) in ansible_local.pki.known_realms %}
|
||||
{% set _ = custom_realm_list.append(domain.split('.')[1:] | join('.')) %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if custom_realm_list | length == 0 %}
|
||||
{% set _ = custom_realm_list.append(fallback_realm) %}
|
||||
{% endif %}
|
||||
{{ custom_realm_list | to_nice_yaml }}
|
||||
{% endmacro %}{# ]]] #}
|
||||
|
||||
{% macro get_apache_version() %}{# [[[ #}
|
||||
{{ ansible_local.apache.version | d("2.4.0") -}}
|
||||
{% endmacro %}{# ]]] #}
|
||||
|
||||
{% macro get_apache_min_version() %}{# [[[ #}
|
||||
{{ ansible_local.apache.min_version | d("2.4.0") -}}
|
||||
{% endmacro %}{# ]]] #}
|
||||
|
||||
{% macro get_openssl_version() %}{# [[[ #}
|
||||
{{ ansible_local.pki.openssl_version | d("0.0.0") }}
|
||||
{% endmacro %}{# ]]] #}
|
||||
|
||||
{% macro get_gnutls_version() %}{# [[[ #}
|
||||
{{ ansible_local.pki.gnutls_version | d("0.0.0") }}
|
||||
{% endmacro %}{# ]]] #}
|
||||
|
||||
{% macro indent(content, width=4, indentfirst=False) %}{# [[[ #}
|
||||
{#
|
||||
## Fixed version of the `indent` filter which does not insert trailing spaces on empty lines.
|
||||
## Note that you can not use this macro like a filter but have to use it like a regular macro.
|
||||
## Example: {{ debops__tpl_macros.indent(some_content, 4) }}
|
||||
##
|
||||
## Python re.sub seems to default to re.MULTILINE in Ansible.
|
||||
#}
|
||||
{{ content | indent(width, indentfirst) | regex_replace("[ \\t\\r\\f\\v]+(\\n|$)", "\\1") -}}
|
||||
{% endmacro %}{# ]]] #}
|
||||
|
||||
{% macro merge_dict(current_dict, to_merge_dict, dict_key='name') %}{# [[[ #}
|
||||
{#
|
||||
## Recursively merges nested dictionaries or a nested dictionary with a list of
|
||||
## dictionaries. In the second case, a key name can be given whose value will
|
||||
## be used as top-level key for the dictionary item. Note that for merging simple
|
||||
## dictionaries you should use the regular `combined` Jinja filter.
|
||||
##
|
||||
## This can be used to define default variables as YAML dictionaries and then
|
||||
## use YAML lists of dictionaries either in the inventory or in role dependent
|
||||
## variables which lets you add multiple YAML lists together.
|
||||
##
|
||||
## Arguments:
|
||||
## current_dict: Nested dictionary whose values might get overwritten if
|
||||
## defined in `to_merge_dict`.
|
||||
## to_merge_dict: Dictionary or list of dictionaries being merged into `current_dict`.
|
||||
## dict_key: Key in the `to_merge_dict` item which is used to match the
|
||||
## dictionary item being merged in `current_dict` in case `to_merge_dict`
|
||||
## is a list of dictionaries.
|
||||
##
|
||||
## Return: JSON-formatted dictionary
|
||||
##
|
||||
## Examples:
|
||||
##
|
||||
## 1. Merge single-nested dictionaries:
|
||||
## {{ debops__tmpl_macros.merge_dict({'item1': {'key1': 'val1', 'key2': 'val2'},
|
||||
## 'item2': {'key3': 'val3', 'key4': 'val4'}},
|
||||
## {'item1': {'key2': 'new_val2'},
|
||||
## 'item2': {'key5': 'val5' }}) }}
|
||||
##
|
||||
## Will output: {"item1": {"key1": "val1", "key2": "new_val2"},
|
||||
## "item2": {"key3": "val3", "key4": "val4", "key5": "val5"}}
|
||||
##
|
||||
## 2. Merge double-nested dictionaries:
|
||||
## {{ debops__tmpl_macros.merge_dict({'item1': {'prop1': {'key1': 'val1'}}},
|
||||
## {'item1': {'prop1': {'key3': 'val3'},
|
||||
## 'prop2': {'key2': 'val2'}}}) }}
|
||||
##
|
||||
## Will output: {"item1": {"prop1": {"key1": "val1", "key3": "val3"},
|
||||
## "prop2": {"key2": "val2"}}}
|
||||
##
|
||||
## 3. Merge nested dictionary with list of dictionaries:
|
||||
## {{ debops__tmpl_macros.merge_dict({'item1': {'key1': 'val1', 'key2': 'val2'}},
|
||||
## [{'name': 'item2', 'key3': 'val3'},
|
||||
## {'name': 'item3', 'key4': 'val4'}]) }}
|
||||
##
|
||||
## Will output: {"item1: {"key1": "val1", "key2": "val2"},
|
||||
## "item2: {"name": "item2", "key3": "val3"},
|
||||
## "item3: {"name": "item3", "key4": "val4"}}
|
||||
#}
|
||||
{% set merged_dict = current_dict %}
|
||||
{% if to_merge_dict %}
|
||||
{% if to_merge_dict is mapping %}
|
||||
{% for dict_name in to_merge_dict.keys() | sort %}
|
||||
{% if to_merge_dict[dict_name][dict_key] | d() %}
|
||||
{% set _ = merged_dict.update({to_merge_dict[dict_name][dict_key]:(current_dict[to_merge_dict[dict_name][dict_key]] | d({}) | combine(to_merge_dict[dict_name], recursive=True))}) %}
|
||||
{% elif to_merge_dict[dict_name][dict_key] is undefined %}
|
||||
{% set _ = merged_dict.update({dict_name:(current_dict[dict_name] | d({}) | combine(to_merge_dict[dict_name], recursive=True))}) %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% elif to_merge_dict is not string and to_merge_dict is not mapping %}
|
||||
{% set flattened_dict = lookup("flattened", to_merge_dict) %}
|
||||
{% for element in ([ flattened_dict ] if flattened_dict is mapping else flattened_dict) %}
|
||||
{% if element[dict_key] | d() %}
|
||||
{% set _ = merged_dict.update({element[dict_key]:(current_dict[element[dict_key]] | d({}) | combine(element, recursive=True))}) %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{{ merged_dict | to_yaml }}
|
||||
{% endmacro %}{# ]]] #}
|
||||
|
||||
{% macro flattened() %}{# [[[ #}
|
||||
{# This macro does what the flattened lookup from Ansible fails to do in Jinja templates as of Ansible 2.2.
|
||||
## All macro arguments are flattened into one "flat" list.
|
||||
## Uses a less known feature of Jinja for using the *args and *kwargs syntax as known from
|
||||
## Python. Even if the macro does not declare any arguments, it will happyily
|
||||
## flatten any non-key-value arguments you provide.
|
||||
## Additional key-value arguments can be used to influence the behavior of the macro.
|
||||
## The macro uses recursion to flatten nested lists.
|
||||
## Ref: https://stackoverflow.com/questions/13944751/args-kwargs-in-jinja2-macros
|
||||
## Returns flattened object as JSON which you will need to deserialize using `from_yaml`.
|
||||
## Usage:
|
||||
##
|
||||
## {{ debops__tpl_macros.flattened(['list1', 55, ["deeplist1", "deeplist elem", True, False, undefined], {'mapping': True}], 'raw1', 22, True, False) }}
|
||||
## → ["list1", 55, "deeplist1", "deeplist elem", true, false, "raw1", 22, true, false]
|
||||
##
|
||||
## {{ debops__tpl_macros.flattened(['list1', 55, ["deeplist1", "deeplist elem", True, False, undefined], {'mapping': True}], 'raw1', 22, True, False, filter_undef=False) }}
|
||||
## → ["list1", 55, "deeplist1", "deeplist elem", true, false, null, "raw1", 22, true, false]
|
||||
##
|
||||
## {{ debops__tpl_macros.flattened(['list1', 55, ["deeplist1", "deeplist elem", True, False, undefined], {'mapping': True}], 'raw1', 22, True, False, filter_mapping=False) }}
|
||||
## → ["list1", 55, "deeplist1", "deeplist elem", true, false, {"mapping": true}, "raw1", 22, true, false]
|
||||
##
|
||||
## Ansible versions tested with: 2.1, 2.2
|
||||
## Jinja versions tested with: 2.8.1
|
||||
#}
|
||||
{% set filter_undef = kwargs.filter_undef | d(True) | bool %}
|
||||
{% set filter_mapping = kwargs.filter_mapping | d(True) | bool %}
|
||||
{# The following options are planned but currently don’t work: #}
|
||||
{% set append_mapping_keys = kwargs.append_mapping_keys | d(False) | bool %}
|
||||
{% set append_mapping_values = kwargs.append_mapping_values | d(False) | bool %}
|
||||
{#
|
||||
{{ "filter_undef:" + (filter_undef | string) }}
|
||||
{{ "filter_mapping:" + (filter_mapping | string) }}
|
||||
{{ "varargs:" + (varargs | string) }}
|
||||
#}
|
||||
{% set elem_flattened = [] %}
|
||||
{% for arg in varargs %}
|
||||
{#
|
||||
{{ "arg: " + (arg | string) }}
|
||||
#}
|
||||
{% if filter_undef and (arg is undefined) %}
|
||||
{# Filter out. #}
|
||||
{% elif append_mapping_keys and (arg is mapping) %}
|
||||
{# Does not work as of Jinja 2.8? #}
|
||||
{% set _ = elem_flattened.extend(flattened(arg.keys(), filter_undef=filter_undef, filter_mapping=filter_mapping) | from_yaml) %}
|
||||
{% elif append_mapping_values and (arg is mapping) %}
|
||||
{# Does not work as of Jinja 2.8? #}
|
||||
{% set _ = elem_flattened.extend(flattened(arg.values(), filter_undef=filter_undef, filter_mapping=filter_mapping) | from_yaml) %}
|
||||
{% elif filter_mapping and (arg is mapping) %}
|
||||
{# Filter out. #}
|
||||
{% elif (arg is undefined) %}
|
||||
{% set _ = elem_flattened.append(None) %}
|
||||
{% elif (arg is string) or (arg is number) or (arg is sameas True) or (arg is sameas False) or (arg is mapping) %}
|
||||
{% set _ = elem_flattened.append(arg) %}
|
||||
{% elif (arg is iterable) %}
|
||||
{% for element in arg %}
|
||||
{% set _ = elem_flattened.extend(flattened(element, filter_undef=filter_undef, filter_mapping=filter_mapping) | from_yaml) %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{{ elem_flattened | to_yaml }}
|
||||
{% endmacro %}{# ]]] #}
|
||||
Loading…
Reference in a new issue