Fixes serialization issues with the ini files. Still has an unhealthy dependency on odict() and cannot recurse its method. Macro.jinja has additional methods that should also be pruned once
This commit is contained in:
parent
0b65d5aaea
commit
c2435a397f
@ -1,21 +1,26 @@
|
|||||||
{%- macro php_block(section, settings) %}
|
{%- macro php_block(config) %}
|
||||||
|
{% for sections in config %}
|
||||||
{%- if settings is number or settings is string %}
|
{%- 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() -%}
|
{%- for setting in settings -%}
|
||||||
{%- if value is number or value is string %}
|
{%- for key, value in setting.items() %}
|
||||||
{{ setting }} = {{ value }}
|
{%- if value is number or value is string %}
|
||||||
{%- elif value is iterable -%}
|
{{ key }} = {{ value }}
|
||||||
{%- if setting == 'error_reporting' %}
|
{%- elif value is iterable -%}
|
||||||
{{ setting }} = {{ value|join(" & ") }}
|
{%- if key == 'error_reporting' %}
|
||||||
{%- else %}
|
{{ key }} = {{ value|join(" & ") }}
|
||||||
{{ setting }} = {{ value|join(",") }}
|
{%- else %}
|
||||||
{%- endif -%}
|
{{ key }} = {{ value|join(",") }}
|
||||||
{%- endif %}
|
{%- endif -%}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- endfor -%}
|
||||||
|
{%- endfor -%}
|
||||||
|
{%- endif -%}
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
{%- endif -%}
|
{% endfor %}
|
||||||
{%- endmacro -%}
|
{%- endmacro -%}
|
||||||
|
|
||||||
; PHP configuration file.
|
; PHP configuration file.
|
||||||
@ -23,6 +28,4 @@
|
|||||||
; **** 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(config) }}
|
||||||
{{ php_block(section, settings) }}
|
|
||||||
{%- endfor -%}
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# 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) %}
|
||||||
@ -14,7 +15,7 @@ php_fpm_ini_config:
|
|||||||
- 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:
|
||||||
@ -23,4 +24,4 @@ php_fpm_conf_config:
|
|||||||
- 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) }}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# 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/fpm/pools_config.sls' import pool_states 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 %}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# 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) -%}
|
||||||
@ -20,7 +21,7 @@
|
|||||||
- 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 }}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
# 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:
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
# 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:
|
||||||
@ -9,4 +10,4 @@ php_ini:
|
|||||||
- 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) }}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
# 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 }}:
|
||||||
|
68
php/ng/macro.jinja
Normal file
68
php/ng/macro.jinja
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
# 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 -%}
|
@ -1,9 +1,3 @@
|
|||||||
{% 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': {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user