Skip to content

Commit

Permalink
feat(tofs): implementation for all file.managed
Browse files Browse the repository at this point in the history
- Implementation of libtofs on ini macro, pools_config and apache2 mod_php.conf
+ Introduction of tplroot on modified files
+ `{%-` consistency when possible
  • Loading branch information
sticky-note authored and myii committed Sep 13, 2019
1 parent bb199b1 commit 8e79a35
Show file tree
Hide file tree
Showing 13 changed files with 834 additions and 102 deletions.
518 changes: 518 additions & 0 deletions docs/TOFS_pattern.rst

Large diffs are not rendered by default.

File renamed without changes.
17 changes: 11 additions & 6 deletions php/apache2/ini.sls
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Manages the main Apache2 ini file
{% from "php/map.jinja" import php with context %}
{% from "php/ini.jinja" import php_ini %}
{#- Manages the main Apache2 ini file #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import php with context %}
{%- from tplroot ~ "/ini.jinja" import php_ini %}

{% set settings = php.ini.defaults %}
{% do settings.update(php.apache2.ini.settings) %}
{%- set settings = php.ini.defaults %}
{%- do settings.update(php.apache2.ini.settings) %}

php_apache2_ini:
{{ php_ini(php.lookup.apache2.ini, php.apache2.ini.opts, settings) }}
{{ php_ini(php.lookup.apache2.ini,
'php_apache2_ini',
php.apache2.ini.opts,
settings
) }}
21 changes: 13 additions & 8 deletions php/apache2/install.sls
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
{% from "php/map.jinja" import php with context %}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import php with context %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
{% set state = 'apache2' %}
{% include "php/installed.jinja" %}
{%- set state = 'apache2' %}
{%- include tplroot ~ "/installed.jinja" %}
{% if grains['os_family'] == "FreeBSD" %}
{%- if grains['os_family'] == "FreeBSD" %}
{{ php.lookup.apache2.module_config }}:
file.managed:
- source: salt://php/apache2/files/mod_php.conf.jinja
- source: {{ files_switch(['mod_php.conf.jinja'],
lookup='php_apache2_module_config',
use_subpath=True
) }}
- template: jinja
{% if salt['pillar.get']('php:use_apache_formula', True) %}
{%- if salt['pillar.get']('php:use_apache_formula', True) %}
- makedirs: true
- require_in:
- sls: apache
- watch_in:
- module: apache-restart
{% endif %} #END: use apache formula
{% endif %} #END: os = debian
{%- endif %} #END: use apache formula
{%- endif %} #END: os = debian
51 changes: 30 additions & 21 deletions php/cli/ini.sls
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
# Manages the php cli main ini file
{% from "php/map.jinja" import php with context %}
{% from "php/ini.jinja" import php_ini %}
{#- Manages the php cli main ini file #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import php with context %}
{%- from tplroot ~ "/ini.jinja" import php_ini %}
{% set settings = php.ini.defaults %}
{% for key, value in php.cli.ini.settings.items() %}
{% if settings[key] is defined %}
{% do settings[key].update(value) %}
{% else %}
{% do settings.update({key: value}) %}
{% endif %}
{% endfor %}
{%- set settings = php.ini.defaults %}
{%- for key, value in php.cli.ini.settings.items() %}
{%- if settings[key] is defined %}
{%- do settings[key].update(value) %}
{%- else %}
{%- do settings.update({key: value}) %}
{%- endif %}
{%- endfor %}
{% set pillar_php_version = salt['pillar.get']('php:version', '7.0') %}
{% if pillar_php_version is iterable and pillar_php_version is not string %}
{% for version in pillar_php_version %}
{% set first_version = pillar_php_version[0]|string %}
{% set ini = php.lookup.cli.ini|replace(first_version, version) %}
{%- set pillar_php_version = salt['pillar.get']('php:version', '7.0') %}
{%- if pillar_php_version is iterable and pillar_php_version is not string %}
{%- for version in pillar_php_version %}
{%- set first_version = pillar_php_version[0]|string %}
{%- set ini = php.lookup.cli.ini|replace(first_version, version) %}
php_cli_ini_{{ version }}:
{{ php_ini(ini, php.cli.ini.opts, settings) }}
{% endfor %}
{% else %}
{{ php_ini(ini,
'php_cli_ini_' ~ version,
php.cli.ini.opts,
settings
) }}
{%- endfor %}
{%- else %}
php_cli_ini:
{{ php_ini(php.lookup.cli.ini, php.cli.ini.opts, settings) }}
{% endif %}
{{ php_ini(php.lookup.cli.ini,
'php_cli_ini',
php.cli.ini.opts,
settings
) }}
{%- endif %}
File renamed without changes.
93 changes: 55 additions & 38 deletions php/fpm/config.sls
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
# Manages the php-fpm main ini file
{% from 'php/map.jinja' import php with context %}
{% from "php/ini.jinja" import php_ini %}
{% set ini_settings = php.ini.defaults %}
{% for key, value in php.fpm.config.ini.settings.items() %}
{% if ini_settings[key] is defined %}
{% do ini_settings[key].update(value) %}
{% else %}
{% do ini_settings.update({key: value}) %}
{% endif %}
{% endfor %}
{% set pillar_php_version = salt['pillar.get']('php:version', '7.0') %}
{% if pillar_php_version is iterable and pillar_php_version is not string %}
{% for version in pillar_php_version %}
{% set conf_settings = odict(php.lookup.fpm.defaults) %}
{% set first_version = pillar_php_version[0]|string %}
{% set ini = php.lookup.fpm.ini|replace(first_version, version) %}
{% set conf = php.lookup.fpm.conf|replace(first_version, version) %}
{% set pools = php.lookup.fpm.pools|replace(first_version, version) %}
{% for key, value in conf_settings.items() %}
{% if value is string %}
{% do conf_settings.update({key: value.replace(first_version, version)}) %}
{% endif %}
{% endfor %}
{% do conf_settings.global.update({'pid': '/var/run/php' + version + '-fpm.pid' }) %}
{% do conf_settings.global.update({'error_log': '/var/log/php' + version + '-fpm.log' }) %}
{#- Manages the php-fpm main ini file #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import php with context %}
{%- from tplroot ~ "/ini.jinja" import php_ini %}
{%- set ini_settings = php.ini.defaults %}
{%- for key, value in php.fpm.config.ini.settings.items() %}
{%- if ini_settings[key] is defined %}
{%- do ini_settings[key].update(value) %}
{%- else %}
{%- do ini_settings.update({key: value}) %}
{%- endif %}
{%- endfor %}
{%- set pillar_php_version = salt['pillar.get']('php:version', '7.0') %}
{%- if pillar_php_version is iterable and pillar_php_version is not string %}
{%- for version in pillar_php_version %}
{%- set conf_settings = odict(php.lookup.fpm.defaults) %}
{%- set first_version = pillar_php_version[0]|string %}
{%- set ini = php.lookup.fpm.ini|replace(first_version, version) %}
{%- set conf = php.lookup.fpm.conf|replace(first_version, version) %}
{%- set pools = php.lookup.fpm.pools|replace(first_version, version) %}
{%- for key, value in conf_settings.items() %}
{%- if value is string %}
{%- do conf_settings.update({key: value.replace(first_version, version)}) %}
{%- endif %}
{%- endfor %}
{%- do conf_settings.global.update({'pid': '/var/run/php' + version + '-fpm.pid' }) %}
{%- do conf_settings.global.update({'error_log': '/var/log/php' + version + '-fpm.log' }) %}
php_fpm_ini_config_{{ version }}:
{{ php_ini(ini, php.fpm.config.ini.opts, ini_settings) }}
{{ php_ini(ini,
'php_fpm_ini_config_' ~ version,
php.fpm.config.ini.opts,
ini_settings
) }}
php_fpm_conf_config_{{ version }}:
{{ php_ini(conf, php.fpm.config.conf.opts, odict(conf_settings)) }}
{{ php_ini(conf,
'php_fpm_conf_config_' ~ version,
php.fpm.config.conf.opts,
odict(conf_settings)
) }}
{{ pools }}:
file.directory:
Expand All @@ -41,17 +50,25 @@ php_fpm_conf_config_{{ version }}:
- group: {{ php.lookup.fpm.group }}
- file_mode: 755
- make_dirs: True
{% endfor %}
{% else %}
{%- endfor %}
{%- else %}
{% set conf_settings = php.lookup.fpm.defaults %}
{% do conf_settings.update(php.fpm.config.conf.settings) %}
{%- set conf_settings = php.lookup.fpm.defaults %}
{%- do conf_settings.update(php.fpm.config.conf.settings) %}
php_fpm_ini_config:
{{ php_ini(php.lookup.fpm.ini, php.fpm.config.ini.opts, ini_settings) }}
{{ php_ini(php.lookup.fpm.ini,
'php_fpm_ini_config',
php.fpm.config.ini.opts,
ini_settings
) }}
php_fpm_conf_config:
{{ php_ini(php.lookup.fpm.conf, php.fpm.config.conf.opts, conf_settings) }}
{{ php_ini(php.lookup.fpm.conf,
'php_fpm_conf_config',
php.fpm.config.conf.opts,
conf_settings
) }}
{{ php.lookup.fpm.pools }}:
file.directory:
Expand All @@ -60,4 +77,4 @@ php_fpm_conf_config:
- group: {{ php.lookup.fpm.group }}
- file_mode: 755
- make_dirs: True
{% endif %}
{%- endif %}
14 changes: 9 additions & 5 deletions php/fpm/pools_config.sls
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Manages the php-fpm pools config files
{% from 'php/map.jinja' import php with context %}
{% from "php/macro.jinja" import sls_block, serialize %}
{#- Manages the php-fpm pools config files #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import php with context %}
{%- from tplroot ~ "/macro.jinja" import sls_block, serialize %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
# Simple path concatenation.
{#- Simple path concatenation. #}
{% macro path_join(file, root) -%}
{{ root ~ '/' ~ file }}
{%- endmacro %}
Expand Down Expand Up @@ -32,7 +34,9 @@
file.managed:
{{ sls_block(config.get('opts', {})) }}
- name: {{ fpath }}
- source: salt://php/files/php.ini
- source: {{ files_switch(['php.ini'],
'php_fpm_pool_conf'
) }}
- template: jinja
- context:
config: {{ serialize(config.get('settings', {})) }}
Expand Down
26 changes: 17 additions & 9 deletions php/hhvm/config.sls
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# Manages the php-hhvm main ini file
{% from "php/map.jinja" import php with context %}
{% from "php/ini.jinja" import php_ini %}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import php with context %}
{%- from tplroot ~ "/ini.jinja" import php_ini %}
{% set server_settings = php.lookup.hhvm.server %}
{% do server_settings.update(php.hhvm.config.server.settings) %}
{%- set server_settings = php.lookup.hhvm.server %}
{%- do server_settings.update(php.hhvm.config.server.settings) %}
{% set php_settings = php.lookup.hhvm.php %}
{% do php_settings.update(php.hhvm.config.php.settings) %}
{%- set php_settings = php.lookup.hhvm.php %}
{%- do php_settings.update(php.hhvm.config.php.settings) %}
php_hhvm_ini_config:
{{ php_ini(php.lookup.hhvm.conf, php.hhvm.config.server.opts, server_settings) }}
{{ php_ini(php.lookup.hhvm.conf,
'php_hhvm_ini_config',
php.hhvm.config.server.opts,
server_settings
) }}
php_hhvm_conf_config:
{{ php_ini(php.lookup.hhvm.ini, php.hhvm.config.php.opts, php_settings) }}
{{ php_ini(php.lookup.hhvm.ini,
'php_hhvm_conf_config',
php.hhvm.config.php.opts,
php_settings
) }}
12 changes: 8 additions & 4 deletions php/ini.jinja
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# -*- coding: utf-8 -*-
# vim: ft=jinja
{# php.ini management macro. #}
{% from "php/macro.jinja" import sls_block, serialize %}
{#- php.ini management macro. #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/macro.jinja" import sls_block, serialize %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}

{% macro php_ini(filename, opts={}, settings={}) %}
{% macro php_ini(filename, tofs_lookup, opts={}, settings={}) %}
file.managed:
{{ sls_block(opts) }}
- name: {{ filename }}
- source: salt://php/files/php.ini
- source: {{ files_switch(['php.ini'],
tofs_lookup
) }}
- template: jinja
- context:
config: {{ serialize(odict(settings)) }}
Expand Down
Loading

0 comments on commit 8e79a35

Please sign in to comment.