Skip to content

Commit ef25eb9

Browse files
authored
Merge pull request #167 from arthurlogilab/multiphp
[php/ng] support the use of a list of php versions
2 parents d530e81 + 38fe58f commit ef25eb9

File tree

10 files changed

+130
-3
lines changed

10 files changed

+130
-3
lines changed

php/ng/cli/ini.sls

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,16 @@ include:
1414
{% endif %}
1515
{% endfor %}
1616
17+
{% set pillar_php_ng_version = salt['pillar.get']('php:ng:version', '7.0') %}
18+
{% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %}
19+
{% for version in pillar_php_ng_version %}
20+
{% set first_version = pillar_php_ng_version[0]|string %}
21+
{% set ini = php.lookup.cli.ini|replace(first_version, version) %}
22+
php_cli_ini_{{ version }}:
23+
{{ php_ini(ini, php.cli.ini.opts, settings) }}
24+
{% endfor %}
25+
{% else %}
26+
1727
php_cli_ini:
1828
{{ php_ini(php.lookup.cli.ini, php.cli.ini.opts, settings) }}
29+
{% endif %}

php/ng/cli/init.sls

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,19 @@ include:
55
- php.ng.cli.install
66
- php.ng.cli.ini
77

8+
{% set pillar_php_ng_version = salt['pillar.get']('php:ng:version', '7.0') %}
9+
{% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %}
10+
extend:
11+
{% for version in pillar_php_ng_version %}
12+
php_cli_ini_{{ version }}:
13+
file:
14+
- require:
15+
- sls: php.ng.cli.install
16+
{% endfor %}
17+
{% else %}
818
extend:
919
php_cli_ini:
1020
file:
1121
- require:
1222
- sls: php.ng.cli.install
23+
{% endif %}

php/ng/cli/install.sls

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,18 @@ include:
66

77
{%- if salt['grains.get']('os_family') == "Debian" %}
88
{% set current_php = salt['alternatives.show_current']('php') %}
9+
{% set pillar_php_ng_version = salt['pillar.get']('php:ng:version', '7.0') %}
10+
{% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %}
11+
{% if 'alternatives_version' in salt['pillar.get']('php:ng') %}
12+
{% set phpng_version = salt['pillar.get']('php:ng:alternatives_version') %}
13+
{% else %}
14+
{% set phpng_version = false %}
15+
{% endif %}
16+
{% else %}
917
{% set phpng_version = salt['pillar.get']('php:ng:version', '7.0')|string %}
18+
{% endif %}
1019

20+
{% if phpng_version %}
1121
php_{{ phpng_version }}_link:
1222
alternatives.set:
1323
- name: php
@@ -18,3 +28,4 @@ php_{{ phpng_version }}_link:
1828
- which php
1929
- test {{ current_php }} != $(which php{{ phpng_version }})
2030
{% endif %}
31+
{% endif %}

php/ng/fpm/config.sls

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,39 @@ include:
1414
{% endif %}
1515
{% endfor %}
1616
17+
{% set pillar_php_ng_version = salt['pillar.get']('php:ng:version', '7.0') %}
18+
{% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %}
19+
{% for version in pillar_php_ng_version %}
20+
{% set conf_settings = odict(php.lookup.fpm.defaults) %}
21+
{% set first_version = pillar_php_ng_version[0]|string %}
22+
{% set ini = php.lookup.fpm.ini|replace(first_version, version) %}
23+
{% set conf = php.lookup.fpm.conf|replace(first_version, version) %}
24+
{% set pools = php.lookup.fpm.pools|replace(first_version, version) %}
25+
26+
{% for key, value in conf_settings.items() %}
27+
{% if value is string %}
28+
{% do conf_settings.update({key: value.replace(first_version, version)}) %}
29+
{% endif %}
30+
{% endfor %}
31+
{% do conf_settings.global.update({'pid': '/var/run/php' + version + '-fpm.pid' }) %}
32+
{% do conf_settings.global.update({'error_log': '/var/log/php' + version + '-fpm.log' }) %}
33+
34+
php_fpm_ini_config_{{ version }}:
35+
{{ php_ini(ini, php.fpm.config.ini.opts, ini_settings) }}
36+
37+
php_fpm_conf_config_{{ version }}:
38+
{{ php_ini(conf, php.fpm.config.conf.opts, odict(conf_settings)) }}
39+
40+
{{ pools }}:
41+
file.directory:
42+
- name: {{ pools }}
43+
- user: {{ php.lookup.fpm.user }}
44+
- group: {{ php.lookup.fpm.group }}
45+
- file_mode: 755
46+
- make_dirs: True
47+
{% endfor %}
48+
{% else %}
49+
1750
{% set conf_settings = php.lookup.fpm.defaults %}
1851
{% do conf_settings.update(php.fpm.config.conf.settings) %}
1952
@@ -30,3 +63,4 @@ php_fpm_conf_config:
3063
- group: {{ php.lookup.fpm.group }}
3164
- file_mode: 755
3265
- make_dirs: True
66+
{% endif %}

php/ng/fpm/init.sls

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,34 @@ include:
66
- php.ng.fpm.service
77
- php.ng.fpm.pools
88

9+
{% set pillar_php_ng_version = salt['pillar.get']('php:ng:version', '7.0') %}
910
extend:
1011
php_fpm_service:
1112
service:
1213
- watch:
14+
{% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %}
15+
{% for version in pillar_php_ng_version %}
16+
- file: php_fpm_ini_config_{{ version }}
17+
- file: php_fpm_conf_config_{{ version }}
18+
{% endfor %}
19+
{% else %}
1320
- file: php_fpm_ini_config
1421
- file: php_fpm_conf_config
22+
{% endif %}
1523
- require:
1624
- sls: php.ng.fpm.config
25+
{% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %}
26+
{% for version in pillar_php_ng_version %}
27+
php_fpm_ini_config_{{ version }}:
28+
file:
29+
- require:
30+
- pkg: php_install_fpm
31+
php_fpm_conf_config_{{ version }}:
32+
file:
33+
- require:
34+
- pkg: php_install_fpm
35+
{% endfor %}
36+
{% else %}
1737
php_fpm_ini_config:
1838
file:
1939
- require:
@@ -22,3 +42,4 @@ extend:
2242
file:
2343
- require:
2444
- pkg: php_install_fpm
45+
{% endif %}

php/ng/fpm/pools_config.sls

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ include:
2020
{% do pvalues.update(pool_defaults) %}
2121
{% endfor %}
2222
{% set state = 'php_fpm_pool_conf_' ~ loop.index0 %}
23-
{% set fpath = path_join(config.get('filename', pool), php.lookup.fpm.pools) %}
23+
24+
{% set pillar_php_ng_version = salt['pillar.get']('php:ng:version', '7.0') %}
25+
{% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %}
26+
{% set first_fpath = path_join(config.get('filename', pool), php.lookup.fpm.pools) %}
27+
{% set first_version = pillar_php_ng_version[0]|string %}
28+
{% set fpath = first_fpath.replace(first_version, config.get('phpversion', '7.0')) %}
29+
{% else %}
30+
{% set fpath = path_join(config.get('filename', pool), php.lookup.fpm.pools) %}
31+
{% endif %}
2432
2533
{{ state }}:
2634
{% if config.enabled %}

php/ng/ini.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
- source: salt://php/ng/files/php.ini
1111
- template: jinja
1212
- context:
13-
config: {{ serialize(settings) }}
13+
config: {{ serialize(odict(settings)) }}
1414
{%- endmacro -%}

php/ng/installed.jinja

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,31 @@ include:
1212
{% set pkgs = [] %}
1313
{% set specials = [] %}
1414

15+
{% set pillar_php_ng_version = salt['pillar.get']('php:ng:version', '7.0') %}
1516
{% if pkginfo is iterable and pkginfo is not string %}
1617
{% for pkg in pkginfo %}
1718
{% if pkg is mapping %}
1819
{% do specials.append(pkg) %}
1920
{% else %}
2021
{% do pkgs.append(pkg) %}
22+
{% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %}
23+
{% set first_version = pillar_php_ng_version[0]|string %}
24+
{% for other_version in pillar_php_ng_version %}
25+
{% set other_version_str = other_version|string %}
26+
{% do pkgs.append(pkg.replace(first_version, other_version_str)) %}
27+
{% endfor %}
28+
{% endif %}
2129
{% endif %}
2230
{% endfor %}
2331
{% else %}
2432
{% do pkgs.append(pkginfo) %}
33+
{% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %}
34+
{% set first_version = pillar_php_ng_version[0]|string %}
35+
{% for other_version in pillar_php_ng_version %}
36+
{% set other_version_str = other_version|string %}
37+
{% do pkgs.append(pkginfo.replace(first_version, other_version_str)) %}
38+
{% endfor %}
39+
{% endif %}
2540
{% endif %}
2641

2742
{% if grains['os_family'] == "Debian" and (state == 'cli' or state == 'fpm' or state == 'php') %}

php/ng/map.jinja

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# -*- coding: utf-8 -*-
22
# vim: ft=jinja
33

4-
{%- set phpng_version = salt['pillar.get']('php:ng:version', '7.0')|string %}
4+
{% set pillar_php_ng_version = salt['pillar.get']('php:ng:version', '7.0') %}
5+
{%- if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %}
6+
{%- set phpng_version = pillar_php_ng_version[0]|string %}
7+
{% else %}
8+
{%- set phpng_version = pillar_php_ng_version|string %}
9+
{% endif %}
510
{%- set freebsd_phpng_version = phpng_version.replace('.', '') %}
611

712
{%- if salt['grains.get']('os') == "Ubuntu" %}

pillar.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ php:
2020
# when you add the php.mongo formula to your execution list
2121
mongo_version: "1.5.5"
2222
ng:
23+
# set the version of php to be used
24+
version: "7.3"
25+
# can be a list of versions :
26+
# version:
27+
# - "7.3"
28+
# - "7.2"
29+
30+
# set the version for the Debian alternatives system, when using a list of versions,
31+
# php:ng:version is used otherwise.
32+
alternatives_version: "7.3"
33+
2334
# this section contains mostly grain filtered data, while overrides
2435
# are possible in the pillar for unique cases, if your OS is not
2536
# represented, please consider adding it to the map.jinja for

0 commit comments

Comments
 (0)