{%- macro php_block(section, settings) %} | |||||
{%- if settings is number or settings is string %} | |||||
{%- macro php_block(config) %} | |||||
{% for sections in config %} | |||||
{%- for section, settings in sections.items() -%} | |||||
{%- if settings is number or settings is string %} | |||||
{{ section }} = {{ settings }} | {{ section }} = {{ settings }} | ||||
{%- else %} | |||||
{%- else %} | |||||
[{{ section }}] | [{{ section }}] | ||||
{%- for setting, value in settings.items() -%} | |||||
{%- if value is number or value is string %} | |||||
{{ setting }} = {{ value }} | |||||
{%- elif value is iterable -%} | |||||
{%- if setting == 'error_reporting' %} | |||||
{{ setting }} = {{ value|join(" & ") }} | |||||
{%- else %} | |||||
{{ setting }} = {{ value|join(",") }} | |||||
{%- endif -%} | |||||
{%- endif %} | |||||
{%- for setting in settings -%} | |||||
{%- for key, value in setting.items() %} | |||||
{%- if value is number or value is string %} | |||||
{{ key }} = {{ value }} | |||||
{%- elif value is iterable -%} | |||||
{%- if key == 'error_reporting' %} | |||||
{{ key }} = {{ value|join(" & ") }} | |||||
{%- else %} | |||||
{{ key }} = {{ value|join(",") }} | |||||
{%- endif -%} | |||||
{%- endif -%} | |||||
{%- endfor -%} | |||||
{%- endfor -%} | |||||
{%- endif -%} | |||||
{%- endfor -%} | {%- endfor -%} | ||||
{%- endif -%} | |||||
{% endfor %} | |||||
{%- endmacro -%} | {%- endmacro -%} | ||||
; PHP configuration file. | ; PHP configuration file. | ||||
; **** DO NOT EDIT THIS FILE **** | ; **** DO NOT EDIT THIS FILE **** | ||||
; | ; | ||||
; This file is managed by Salt | ; This file is managed by Salt | ||||
{%- for section, settings in config.items() -%} | |||||
{{ php_block(section, settings) }} | |||||
{%- endfor -%} | |||||
{{ php_block(config) }} |
# Manages the php-fpm main ini file | # Manages the php-fpm main ini file | ||||
{% from 'php/ng/map.jinja' import php, sls_block with context %} | |||||
{% from 'php/ng/map.jinja' import php with context %} | |||||
{% from "php/ng/macro.jinja" import sls_block, serialize %} | |||||
{% set ini_settings = php.ini.defaults %} | {% set ini_settings = php.ini.defaults %} | ||||
{% do ini_settings.update(php.fpm.config.ini.settings) %} | {% do ini_settings.update(php.fpm.config.ini.settings) %} | ||||
- source: salt://php/ng/files/php.ini | - source: salt://php/ng/files/php.ini | ||||
- template: jinja | - template: jinja | ||||
- context: | - context: | ||||
config: {{ ini_settings }} | |||||
config: {{ serialize(ini_settings) }} | |||||
php_fpm_conf_config: | php_fpm_conf_config: | ||||
file.managed: | file.managed: | ||||
- source: salt://php/ng/files/php.ini | - source: salt://php/ng/files/php.ini | ||||
- template: jinja | - template: jinja | ||||
- context: | - context: | ||||
config: {{ conf_settings }} | |||||
config: {{ serialize(conf_settings) }} |
# Manages the php-fpm pools config files | # Manages the php-fpm pools config files | ||||
{% from 'php/ng/map.jinja' import php, sls_block with context %} | |||||
{% from 'php/ng/fpm/pools_config.sls' import pool_states with context %} | |||||
{% from "php/ng/map.jinja" import php with context %} | |||||
{% from "php/ng/macro.jinja" import sls_block %} | |||||
{% from "php/ng/fpm/pools_config.sls" import pool_states with context %} | |||||
{% macro file_requisites(states) %} | {% macro file_requisites(states) %} | ||||
{%- for state in states %} | {%- for state in states %} |
# Manages the php-fpm pools config files | # Manages the php-fpm pools config files | ||||
{% from 'php/ng/map.jinja' import php, sls_block with context %} | |||||
{% from 'php/ng/map.jinja' import php with context %} | |||||
{% from "php/ng/macro.jinja" import sls_block, serialize %} | |||||
# Simple path concatenation. | # Simple path concatenation. | ||||
{% macro path_join(file, root) -%} | {% macro path_join(file, root) -%} | ||||
- source: salt://php/ng/files/php.ini | - source: salt://php/ng/files/php.ini | ||||
- template: jinja | - template: jinja | ||||
- context: | - context: | ||||
config: {{ config.settings }} | |||||
config: {{ serialize(config.settings) }} | |||||
{% else %} | {% else %} | ||||
file.absent: | file.absent: | ||||
- name: {{ fpath }} | - name: {{ fpath }} |
# Manages the php-fpm service. | # Manages the php-fpm service. | ||||
{% from 'php/ng/map.jinja' import php, sls_block with context %} | |||||
{% from "php/ng/map.jinja" import php with context %} | |||||
{% from "php/ng/macro.jinja" import sls_block %} | |||||
{% set service_function = {True:'running', False:'dead'}.get(php.fpm.service.enabled) %} | {% set service_function = {True:'running', False:'dead'}.get(php.fpm.service.enabled) %} | ||||
include: | include: |
# php.ng.ini.sls | # php.ng.ini.sls | ||||
# | # | ||||
# Generic php.ini management state. | # Generic php.ini management state. | ||||
{% from "php/ng/map.jinja" import php, sls_block with context %} | |||||
{% from "php/ng/map.jinja" import php with context %} | |||||
{% from "php/ng/macro.jinja" import sls_block, serialize %} | |||||
php_ini: | php_ini: | ||||
file.managed: | file.managed: | ||||
- source: salt://php/ng/files/php.ini | - source: salt://php/ng/files/php.ini | ||||
- template: jinja | - template: jinja | ||||
- context: | - context: | ||||
config: {{ php.ini.settings }} | |||||
config: {{ serialize(php.ini.settings) }} |
# Template for installing packages. | # Template for installing packages. | ||||
{% from "php/ng/map.jinja" import php, sls_block with context %} | |||||
{% from "php/ng/map.jinja" import php with context %} | |||||
{% from "php/ng/macro.jinja" import sls_block %} | |||||
{% set opts = php.installed.get(state, {}) %} | {% set opts = php.installed.get(state, {}) %} | ||||
php_install_{{ state }}: | php_install_{{ state }}: |
# Returns a generic block of values suitable for inclusion in most states. | |||||
{% macro sls_block(dict, ind=4) %} | |||||
{% for key, value in dict.items() %} | |||||
{{ '-'|indent(ind, True) }} {{ key }}: {{ value|json() }} | |||||
{% endfor %} | |||||
{% endmacro %} | |||||
# Serializes dicts into sequenced data | |||||
{%- macro serialize(data) -%} | |||||
{%- if data is mapping -%} | |||||
{%- set ret = [] -%} | |||||
{%- for key, value in data.items() -%} | |||||
{%- set value = serialize(value)|load_json() -%} | |||||
{%- do ret.append({key: value}) -%} | |||||
{%- endfor -%} | |||||
{%- elif data is iterable and data is not string -%} | |||||
{%- set ret = [] -%} | |||||
{%- for value in data -%} | |||||
{%- set value = serialize(value)|load_json() -%} | |||||
{%- do ret.append(value) -%} | |||||
{%- endfor -%} | |||||
{%- else -%} | |||||
{% set ret = data %} | |||||
{%- endif -%} | |||||
{{ ret|json() }} | |||||
{%- endmacro -%} | |||||
{%- macro deserialize(data) -%} | |||||
{%- if data is mapping -%} | |||||
{%- set ret = odict([]) -%} | |||||
{%- for key, value in data.items() -%} | |||||
{%- do ret.update({key: deserialize(value)}) -%} | |||||
{%- endfor -%} | |||||
{%- elif data is iterable and data is not string -%} | |||||
{%- if is_list_skd(data)|int() == 1 -%} | |||||
{%- set ret = odict([]) -%} | |||||
{%- for item in data -%} | |||||
{%- for key, value in item.items() -%} | |||||
{% do ret.update({key: deserialize(value)}) %} | |||||
{%- endfor -%} | |||||
{%- endfor -%} | |||||
{%- else -%} | |||||
{%- set ret = [] -%} | |||||
{%- for item in data -%} | |||||
{%- do ret.append(deserialize(item)) -%} | |||||
{%- endfor -%} | |||||
{%- endif -%} | |||||
{%- else -%} | |||||
{% set ret = data %} | |||||
{%- endif -%} | |||||
{{ ret }} | |||||
{%- endmacro -%} | |||||
# and is not number and is mapping and item|length() == 1 | |||||
{%- macro is_list_skd(list) -%} | |||||
{% set ret = 0 %} | |||||
{%- set skds = {'counter': 0} -%} | |||||
{%- for item in list if item is mapping and item|length() == 1 -%} | |||||
{%- do skds.update({'counter': (skds.counter + 1)}) -%} | |||||
{%- endfor -%} | |||||
{%- if skds.counter == list|length() -%} | |||||
{% set ret = 1 %} | |||||
{%- endif -%} | |||||
{{ ret }} | |||||
{%- endmacro -%} |
{% macro sls_block(dict) %} | |||||
{% for key, value in dict.items() %} | |||||
- {{ key }}: {{ value|json() }} | |||||
{% endfor %} | |||||
{% endmacro %} | |||||
{% set php = salt['pillar.get']('php:ng', { | {% set php = salt['pillar.get']('php:ng', { | ||||
'lookup': salt['grains.filter_by']({ | 'lookup': salt['grains.filter_by']({ | ||||
'Debian': { | 'Debian': { |