Bladeren bron

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

tags/v0.34.0
Chad Heuschober 10 jaren geleden
bovenliggende
commit
c2435a397f
9 gewijzigde bestanden met toevoegingen van 108 en 35 verwijderingen
  1. +21
    -18
      php/ng/files/php.ini
  2. +4
    -3
      php/ng/fpm/config.sls
  3. +3
    -2
      php/ng/fpm/pools.sls
  4. +3
    -2
      php/ng/fpm/pools_config.sls
  5. +3
    -1
      php/ng/fpm/service.sls
  6. +3
    -2
      php/ng/ini.sls
  7. +3
    -1
      php/ng/installed.jinja
  8. +68
    -0
      php/ng/macro.jinja
  9. +0
    -6
      php/ng/map.jinja

+ 21
- 18
php/ng/files/php.ini Bestand weergeven

@@ -1,21 +1,26 @@
{%- 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 }}
{%- else %}
{%- else %}
[{{ 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 -%}
{%- endif -%}
{% endfor %}
{%- endmacro -%}

; PHP configuration file.
@@ -23,6 +28,4 @@
; **** DO NOT EDIT THIS FILE ****
;
; This file is managed by Salt
{%- for section, settings in config.items() -%}
{{ php_block(section, settings) }}
{%- endfor -%}
{{ php_block(config) }}

+ 4
- 3
php/ng/fpm/config.sls Bestand weergeven

@@ -1,5 +1,6 @@
# 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 %}
{% do ini_settings.update(php.fpm.config.ini.settings) %}
@@ -14,7 +15,7 @@ php_fpm_ini_config:
- source: salt://php/ng/files/php.ini
- template: jinja
- context:
config: {{ ini_settings }}
config: {{ serialize(ini_settings) }}

php_fpm_conf_config:
file.managed:
@@ -23,4 +24,4 @@ php_fpm_conf_config:
- source: salt://php/ng/files/php.ini
- template: jinja
- context:
config: {{ conf_settings }}
config: {{ serialize(conf_settings) }}

+ 3
- 2
php/ng/fpm/pools.sls Bestand weergeven

@@ -1,6 +1,7 @@
# 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) %}
{%- for state in states %}

+ 3
- 2
php/ng/fpm/pools_config.sls Bestand weergeven

@@ -1,5 +1,6 @@
# 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.
{% macro path_join(file, root) -%}
@@ -20,7 +21,7 @@
- source: salt://php/ng/files/php.ini
- template: jinja
- context:
config: {{ config.settings }}
config: {{ serialize(config.settings) }}
{% else %}
file.absent:
- name: {{ fpath }}

+ 3
- 1
php/ng/fpm/service.sls Bestand weergeven

@@ -1,5 +1,7 @@
# 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) %}

include:

+ 3
- 2
php/ng/ini.sls Bestand weergeven

@@ -1,7 +1,8 @@
# php.ng.ini.sls
#
# 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:
file.managed:
@@ -9,4 +10,4 @@ php_ini:
- source: salt://php/ng/files/php.ini
- template: jinja
- context:
config: {{ php.ini.settings }}
config: {{ serialize(php.ini.settings) }}

+ 3
- 1
php/ng/installed.jinja Bestand weergeven

@@ -1,5 +1,7 @@
# 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, {}) %}

php_install_{{ state }}:

+ 68
- 0
php/ng/macro.jinja Bestand weergeven

@@ -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 -%}

+ 0
- 6
php/ng/map.jinja Bestand weergeven

@@ -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', {
'lookup': salt['grains.filter_by']({
'Debian': {

Laden…
Annuleren
Opslaan