From cfe623fab4d13451fd1c5832730887d50a12f5f1 Mon Sep 17 00:00:00 2001 From: Clayton Kramer Date: Mon, 19 May 2014 16:54:29 -0400 Subject: [PATCH 01/11] New state for managing the php.ini file. --- php/map.jinja | 2 + php/ng/files/php.ini.jinja | 16 +++ php/ng/ini.sls | 12 +++ php/ng/map_ng.jinja | 216 +++++++++++++++++++++++++++++++++++++ 4 files changed, 246 insertions(+) create mode 100644 php/ng/files/php.ini.jinja create mode 100644 php/ng/ini.sls create mode 100644 php/ng/map_ng.jinja diff --git a/php/map.jinja b/php/map.jinja index 029d76f..50a02d8 100644 --- a/php/map.jinja +++ b/php/map.jinja @@ -23,6 +23,7 @@ 'adodb_pkg': 'php5-adodb', 'pgsql_pkg': 'php5-pgsql', 'ldap_pkg': 'php5-ldap', + 'php_ini': '/etc/php5/apache2/php.ini', }, 'RedHat': { 'php_pkg': 'php', @@ -48,5 +49,6 @@ 'adodb_pkg': 'php-adodb', 'pgsql_pkg': 'php-pgsql', 'ldap_pkg': 'php-ldap', + 'php_ini': '/etc/php.ini', }, }, merge=salt['pillar.get']('php:lookup')) %} diff --git a/php/ng/files/php.ini.jinja b/php/ng/files/php.ini.jinja new file mode 100644 index 0000000..5675f86 --- /dev/null +++ b/php/ng/files/php.ini.jinja @@ -0,0 +1,16 @@ +; This file is managed by Salt, do not edit +; +{%- for section, settings in config|dictsort %} +[{{ section }}] + {%- for setting, value in settings|dictsort %} + {% 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 %} + {%- endfor %} +{% endfor %} diff --git a/php/ng/ini.sls b/php/ng/ini.sls new file mode 100644 index 0000000..bc1fd2b --- /dev/null +++ b/php/ng/ini.sls @@ -0,0 +1,12 @@ +{% from "php/ng/map_ng.jinja" import php with context %} + +php-ini: + file.managed: + - name: {{ php.lookup.php_ini }} + - source: salt://php/ng/files/php.ini.jinja + - user: root + - group: root + - mode: 644 + - template: jinja + - context: + config: {{ php.ini_settings }} \ No newline at end of file diff --git a/php/ng/map_ng.jinja b/php/ng/map_ng.jinja new file mode 100644 index 0000000..eec87d2 --- /dev/null +++ b/php/ng/map_ng.jinja @@ -0,0 +1,216 @@ +{% set php = { + 'lookup': salt['grains.filter_by']({ + 'Debian': { + 'php_pkg': 'php5', + 'apc_pkg': 'php-apc', + 'cgi_pkg': 'php5-cgi', + 'cli_pkg': 'php5-cli', + 'curl_pkg': 'php5-curl', + 'fpm_pkg': 'php5-fpm', + 'gd_pkg': 'php5-gd', + 'mbstring_pkg': 'php5', + 'mcrypt_pkg': 'php5-mcrypt', + 'memcache_pkg': 'php5-memcache', + 'memcached_pkg': 'php5-memcached', + 'mysql_pkg': 'php5-mysql', + 'mysqlnd_pkg': 'php5-mysqlnd', + 'pear_pkg': ' php-pear', + 'soap_pkg': ' php-soap', + 'fpm_service': 'php5-fpm', + 'xml_pkg': ' php5-xml', + 'imagick_pkg': 'php5-imagick', + 'suhosin_pkg': 'php5-suhosin', + 'imap_pkg': 'php5-imap', + 'adodb_pkg': 'php5-adodb', + 'pgsql_pkg': 'php5-pgsql', + 'ldap_pkg': 'php5-ldap', + 'php_ini': '/etc/php5/apache2/php.ini', + }, + 'RedHat': { + 'php_pkg': 'php', + 'apc_pkg': 'php-pecl-apc', + 'cgi_pkg': 'php-cgi', + 'cli_pkg': 'php-cli', + 'curl_pkg': 'curl', + 'fpm_pkg': 'php-fpm', + 'gd_pkg': 'php-gd', + 'mbstring_pkg': 'php-mbstring', + 'mcrypt_pkg': 'php-mcrypt', + 'memcache_pkg': 'php-pecl-memcache', + 'memcached_pkg': 'php-pecl-memcached', + 'mysql_pkg': 'php-mysql', + 'mysqlnd_pkg': 'php-mysqlnd', + 'pear_pkg': ' php-pear', + 'soap_pkg': ' php-soap', + 'fpm_service': 'php-fpm', + 'xml_pkg': ' php-xml', + 'imagick_pkg': 'php-imagick', + 'suhosin_pkg': 'php-suhosin', + 'imap_pkg': 'php-imap', + 'adodb_pkg': 'php-adodb', + 'pgsql_pkg': 'php-pgsql', + 'ldap_pkg': 'php-ldap', + 'php_ini': '/etc/php.ini', + }, +}, merge=salt['pillar.get']('php:lookup')), + 'ini_settings': salt['pillar.get']('php:ini_settings', { + 'PHP': { + 'engine': 'On', + 'short_open_tag': 'Off', + 'asp_tags': 'Off', + 'precision': 14, + 'output_buffering': 4096, + 'zlib.output_compression': 'Off', + 'implicit_flush': 'Off', + 'serialize_precision': 17, + 'disable_functions': ['pcntl_alarm','pcntl_fork','pcntl_waitpid','pcntl_wait','pcntl_wifexited','pcntl_wifstopped','pcntl_wifsignaled', + 'pcntl_wexitstatus','pcntl_wtermsig','pcntl_wstopsig','pcntl_signal','pcntl_signal_dispatch','pcntl_get_last_error','pcntl_strerror', + 'pcntl_sigprocmask','pcntl_sigwaitinfo','pcntl_sigtimedwait','pcntl_exec','pcntl_getpriority','pcntl_setpriority'], + 'zend.enable_gc': 'On', + 'expose_php': 'On', + 'max_execution_time': 30, + 'max_input_time': 60, + 'max_input_nesting_level': 64, + 'max_input_vars': 1000, + 'memory_limit': '128M', + 'error_reporting': ['E_ALL', '~E_DEPRECATED', '~E_STRICT'], + 'display_errors': 'Off', + 'display_startup_errors': 'Off', + 'log_errors': 'On', + 'log_errors_max_len': 1024, + 'ignore_repeated_errors': 'Off', + 'ignore_repeated_source': 'Off', + 'report_memleaks': 'On', + 'track_errors': 'Off', + 'html_errors': 'On', + 'variables_order': 'GPCS', + 'request_order': 'GP', + 'register_argc_argv': 'Off', + 'auto_globals_jit': 'On', + 'post_max_size': '8M', + 'default_mimetype': '"text/html"', + 'enable_dl': 'Off', + 'file_uploads': 'On', + 'upload_max_filesize': '2M', + 'max_file_uploads': 20, + 'allow_url_fopen': 'On', + 'allow_url_include': 'Off', + 'default_socket_timeout': 60 + }, + 'CLI Server': { + 'cli_server.color': 'On' + }, + 'Date': { + 'date.timezone': 'America/New_York' + }, + 'Pdo_mysql': { + 'pdo_mysql.cache_size': 2000 + }, + 'mail function': { + 'SMTP': 'localhost', + 'mail.add_x_header': 'On' + }, + 'SQL': { + 'sql.safe_mode': 'Off' + }, + 'ODBC': { + 'odbc.allow_persistent': 'On', + 'odbc.check_persistent': 'On', + 'odbc.max_persistent': '-1', + 'odbc.max_links': '-1', + 'odbc.defaultlrl': 4096, + 'odbc.defaultbinmode': 1 + }, + 'Interbase': { + 'ibase.allow_persistent': 1, + 'ibase.max_persistent': -1, + 'ibase.max_links': -1, + 'ibase.timestampformat': '"%Y-%m-%d %H:%M:%S"', + 'ibase.dateformat': '"%Y-%m-%d"', + 'ibase.timeformat': '"%H:%M:%S"' + }, + 'MySQL': { + 'mysql.allow_local_infile': 'On', + 'mysql.allow_persistent': 'On', + 'mysql.cache_size': '2000', + 'mysql.max_persistent': -1, + 'mysql.max_links': -1, + 'mysql.connect_timeout': 60, + 'mysql.trace_mode': 'Off' + }, + 'MySQLi': { + 'mysqli.max_persistent': -1, + 'mysqli.allow_persistent': 'On', + 'mysqli.max_links': -1, + 'mysqli.cache_size': 2000, + 'mysqli.default_port': 3306, + 'mysqli.reconnect': 'Off' + }, + 'mysqlnd': { + 'mysqlnd.collect_statistics': 'On', + 'mysqlnd.collect_memory_statistics': 'Off' + }, + 'PostgreSQL': { + 'pgsql.allow_persistent': 'On', + 'pgsql.auto_reset_persistent': 'Off', + 'pgsql.max_persistent': -1, + 'pgsql.max_links': -1, + 'pgsql.ignore_notice': 0, + 'pgsql.log_notice': 0 + }, + 'Sybase-CT': { + 'sybct.allow_persistent': 'On', + 'sybct.max_persistent': -1, + 'sybct.max_links': -1, + 'sybct.min_server_severity': 10, + 'sybct.min_client_severity': 10 + }, + 'bcmath': { + 'bcmath.scale': 0 + }, + 'Session': { + 'session.save_handler': 'files', + 'session.use_strict_mode': 0, + 'session.use_cookies': 1, + 'session.use_only_cookies': 1, + 'session.name': 'PHPSESSID', + 'session.auto_start': 0, + 'session.cookie_lifetime': 0, + 'session.cookie_path': '/', + 'session.serialize_handler': 'php', + 'session.gc_probability': 0, + 'session.gc_divisor': 1000, + 'session.gc_maxlifetime': 1440, + 'session.bug_compat_42': 'Off', + 'session.bug_compat_warn': 'Off', + 'session.cache_limiter': 'nocache', + 'session.cache_expire': '180', + 'session.use_trans_sid': 0, + 'session.hash_function': 0, + 'session.hash_bits_per_character': 5, + 'url_rewriter.tags': '"a=href,area=href,frame=src,input=src,form=fakeentry"' + }, + 'MSSQL': { + 'mssql.allow_persistent': 'On', + 'mssql.max_persistent': -1, + 'mssql.max_links': -1, + 'mssql.min_error_severity': 10, + 'mssql.min_message_severity': 10, + 'mssql.compatibility_mode': 'Off', + 'mssql.secure_connection': 'Off' + }, + 'Tidy': { + 'tidy.clean_output': 'Off' + }, + 'soap': { + 'soap.wsdl_cache_enabled': 1, + 'soap.wsdl_cache_dir': '"/tmp"', + 'soap.wsdl_cache_ttl': 86400, + 'soap.wsdl_cache_limit': 5 + }, + 'ldap': { + 'ldap.max_links': -1 + } + }, merge=True) + +}%} From 5e304544edf82a176a20ff26feb3f4e6c89d412b Mon Sep 17 00:00:00 2001 From: Chad Heuschober Date: Tue, 20 May 2014 15:59:25 -0400 Subject: [PATCH 02/11] Adds full fpm pools management. --- php/ng/adodb.sls | 2 + php/ng/apc.sls | 2 + php/ng/cgi.sls | 2 + php/ng/cli.sls | 2 + php/ng/curl.sls | 2 + php/ng/files/php.ini | 28 +++ php/ng/files/php.ini.jinja | 16 -- php/ng/fpm/config.sls | 26 +++ php/ng/fpm/init.sls | 15 ++ php/ng/fpm/install.sls | 2 + php/ng/fpm/pools.sls | 16 ++ php/ng/fpm/pools_config.sls | 33 ++++ php/ng/fpm/service.sls | 17 ++ php/ng/gd.sls | 2 + php/ng/imagick.sls | 2 + php/ng/imap.sls | 2 + php/ng/ini.sls | 16 +- php/ng/init.sls | 2 + php/ng/installed.jinja | 6 + php/ng/ldap.sls | 2 + php/ng/map.jinja | 336 ++++++++++++++++++++++++++++++++++++ php/ng/map_ng.jinja | 216 ----------------------- php/ng/mbstring.sls | 2 + php/ng/mcrypt.sls | 2 + php/ng/memcache.sls | 2 + php/ng/memcached.sls | 2 + php/ng/mysql.sls | 2 + php/ng/mysqlnd.sls | 2 + php/ng/pear.sls | 2 + php/ng/pgsql.sls | 2 + php/ng/soap.sls | 2 + php/ng/suhosin.sls | 2 + php/ng/xml.sls | 2 + 33 files changed, 529 insertions(+), 240 deletions(-) create mode 100644 php/ng/adodb.sls create mode 100644 php/ng/apc.sls create mode 100644 php/ng/cgi.sls create mode 100644 php/ng/cli.sls create mode 100644 php/ng/curl.sls create mode 100644 php/ng/files/php.ini delete mode 100644 php/ng/files/php.ini.jinja create mode 100644 php/ng/fpm/config.sls create mode 100644 php/ng/fpm/init.sls create mode 100644 php/ng/fpm/install.sls create mode 100644 php/ng/fpm/pools.sls create mode 100644 php/ng/fpm/pools_config.sls create mode 100644 php/ng/fpm/service.sls create mode 100644 php/ng/gd.sls create mode 100644 php/ng/imagick.sls create mode 100644 php/ng/imap.sls create mode 100644 php/ng/init.sls create mode 100644 php/ng/installed.jinja create mode 100644 php/ng/ldap.sls create mode 100644 php/ng/map.jinja delete mode 100644 php/ng/map_ng.jinja create mode 100644 php/ng/mbstring.sls create mode 100644 php/ng/mcrypt.sls create mode 100644 php/ng/memcache.sls create mode 100644 php/ng/memcached.sls create mode 100644 php/ng/mysql.sls create mode 100644 php/ng/mysqlnd.sls create mode 100644 php/ng/pear.sls create mode 100644 php/ng/pgsql.sls create mode 100644 php/ng/soap.sls create mode 100644 php/ng/suhosin.sls create mode 100644 php/ng/xml.sls diff --git a/php/ng/adodb.sls b/php/ng/adodb.sls new file mode 100644 index 0000000..5561747 --- /dev/null +++ b/php/ng/adodb.sls @@ -0,0 +1,2 @@ +{% set state = 'adodb' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/apc.sls b/php/ng/apc.sls new file mode 100644 index 0000000..d1c7f1a --- /dev/null +++ b/php/ng/apc.sls @@ -0,0 +1,2 @@ +{% set state = 'apc' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/cgi.sls b/php/ng/cgi.sls new file mode 100644 index 0000000..655e92a --- /dev/null +++ b/php/ng/cgi.sls @@ -0,0 +1,2 @@ +{% set state = 'cgi' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/cli.sls b/php/ng/cli.sls new file mode 100644 index 0000000..c52a6ef --- /dev/null +++ b/php/ng/cli.sls @@ -0,0 +1,2 @@ +{% set state = 'cli' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/curl.sls b/php/ng/curl.sls new file mode 100644 index 0000000..6ad15ed --- /dev/null +++ b/php/ng/curl.sls @@ -0,0 +1,2 @@ +{% set state = 'curl' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/files/php.ini b/php/ng/files/php.ini new file mode 100644 index 0000000..20ae67e --- /dev/null +++ b/php/ng/files/php.ini @@ -0,0 +1,28 @@ +{%- macro php_block(section, settings) %} + + {%- if settings is number or settings is string %} +{{ section }} = {{ settings }} + {%- 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 %} + {%- endfor -%} + {%- endif -%} +{%- endmacro -%} + +; PHP configuration file. +; +; **** DO NOT EDIT THIS FILE **** +; +; This file is managed by Salt +{%- for section, settings in config.items() -%} +{{ php_block(section, settings) }} +{%- endfor -%} diff --git a/php/ng/files/php.ini.jinja b/php/ng/files/php.ini.jinja deleted file mode 100644 index 5675f86..0000000 --- a/php/ng/files/php.ini.jinja +++ /dev/null @@ -1,16 +0,0 @@ -; This file is managed by Salt, do not edit -; -{%- for section, settings in config|dictsort %} -[{{ section }}] - {%- for setting, value in settings|dictsort %} - {% 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 %} - {%- endfor %} -{% endfor %} diff --git a/php/ng/fpm/config.sls b/php/ng/fpm/config.sls new file mode 100644 index 0000000..fd49961 --- /dev/null +++ b/php/ng/fpm/config.sls @@ -0,0 +1,26 @@ +# Manages the php-fpm main ini file +{% from 'php/ng/map.jinja' import php, sls_block with context %} + +{% set ini_settings = php.ini.defaults %} +{% do ini_settings.update(php.fpm.config.ini.settings) %} + +{% set conf_settings = php.lookup.fpm.defaults %} +{% do conf_settings.update(php.fpm.config.conf.settings) %} + +php_fpm_ini_config: + file.managed: + {{ sls_block(php.fpm.config.ini.opts) }} + - name: {{ php.lookup.fpm.ini }} + - source: salt://php/ng/files/php.ini + - template: jinja + - context: + config: {{ ini_settings }} + +php_fpm_conf_config: + file.managed: + {{ sls_block(php.fpm.config.conf.opts) }} + - name: {{ php.lookup.fpm.conf }} + - source: salt://php/ng/files/php.ini + - template: jinja + - context: + config: {{ conf_settings }} diff --git a/php/ng/fpm/init.sls b/php/ng/fpm/init.sls new file mode 100644 index 0000000..298e969 --- /dev/null +++ b/php/ng/fpm/init.sls @@ -0,0 +1,15 @@ +# php.ng.fpm +# +# Meta-state to fully install php. + +include: + - php.ng.fpm.config + - php.ng.fpm.service + - php.ng.fpm.pools + +extend: + php_fpm_service: + service: + - watch: + - file: php_fpm_ini_config + - file: php_fpm_conf_config diff --git a/php/ng/fpm/install.sls b/php/ng/fpm/install.sls new file mode 100644 index 0000000..6fda19e --- /dev/null +++ b/php/ng/fpm/install.sls @@ -0,0 +1,2 @@ +{% set state = 'fpm' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/fpm/pools.sls b/php/ng/fpm/pools.sls new file mode 100644 index 0000000..c41f45c --- /dev/null +++ b/php/ng/fpm/pools.sls @@ -0,0 +1,16 @@ +# 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/fpm/service.sls' import service_function with context %} + +include: + - php.ng.fpm.service + - php.ng.fpm.pools_config + +extend: + php_fpm_service: + service.{{ service_function }}: + - watch: + {%- for pool in pool_states %} + - file: {{ pool }} + {% endfor -%} diff --git a/php/ng/fpm/pools_config.sls b/php/ng/fpm/pools_config.sls new file mode 100644 index 0000000..61f0ba4 --- /dev/null +++ b/php/ng/fpm/pools_config.sls @@ -0,0 +1,33 @@ +# Manages the php-fpm pools config files +{% from 'php/ng/map.jinja' import php, sls_block with context %} + +# Simple path concatenation. +{% macro path_join(file, root) -%} + {{ root ~ '/' ~ file }} +{%- endmacro %} + +{% set pool_states = [] %} + +{% for pool, config in php.fpm.pools.managed.items() %} +{% set state = 'php_fpm_pool_conf_' ~ loop.index0 %} +{% set fpath = path_join(pool, php.lookup.fpm.pools) %} + +{{ state }}: +{% if config.enabled %} + file.managed: + {{ sls_block(php.fpm.pools.managed_opts) }} + - name: {{ fpath }} + - source: salt://php/ng/files/php.ini + - template: jinja + - context: + config: {{ config.settings }} +{% else %} + file.absent: + - name: {{ fpath }} +{% endif %} + +{% do pool_states.append(state) %} +{% endfor %} + + + diff --git a/php/ng/fpm/service.sls b/php/ng/fpm/service.sls new file mode 100644 index 0000000..b729ebb --- /dev/null +++ b/php/ng/fpm/service.sls @@ -0,0 +1,17 @@ +# Manages the php-fpm service. +{% from 'php/ng/map.jinja' import php, sls_block with context %} +{% set service_function = {True:'running', False:'dead'}.get(php.fpm.service.enabled) %} + +include: + - php.ng.fpm.install + +php_fpm_service: + service.{{ service_function }}: + {{ sls_block(php.fpm.service.opts) }} + - name: {{ php.lookup.fpm.service }} + - enable: {{ php.fpm.service.enabled }} + - require: + - sls: php.ng.fpm.install + - watch: + - pkg: php_install_fpm + diff --git a/php/ng/gd.sls b/php/ng/gd.sls new file mode 100644 index 0000000..fe55c71 --- /dev/null +++ b/php/ng/gd.sls @@ -0,0 +1,2 @@ +{% set state = 'gd' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/imagick.sls b/php/ng/imagick.sls new file mode 100644 index 0000000..7bfcd46 --- /dev/null +++ b/php/ng/imagick.sls @@ -0,0 +1,2 @@ +{% set state = 'imagick' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/imap.sls b/php/ng/imap.sls new file mode 100644 index 0000000..20b015e --- /dev/null +++ b/php/ng/imap.sls @@ -0,0 +1,2 @@ +{% set state = 'imap' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/ini.sls b/php/ng/ini.sls index bc1fd2b..2730a70 100644 --- a/php/ng/ini.sls +++ b/php/ng/ini.sls @@ -1,12 +1,12 @@ -{% from "php/ng/map_ng.jinja" import php with context %} +# php.ng.ini.sls +# +# Generic php.ini management state. +{% from "php/ng/map.jinja" import php, sls_block with context %} -php-ini: +php_ini: file.managed: - - name: {{ php.lookup.php_ini }} - - source: salt://php/ng/files/php.ini.jinja - - user: root - - group: root - - mode: 644 + {{ sls_block(php.ini.file_opts) }} + - source: salt://php/ng/files/php.ini - template: jinja - context: - config: {{ php.ini_settings }} \ No newline at end of file + config: {{ php.ini.settings }} diff --git a/php/ng/init.sls b/php/ng/init.sls new file mode 100644 index 0000000..80bd5da --- /dev/null +++ b/php/ng/init.sls @@ -0,0 +1,2 @@ +{% set state = 'php' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/installed.jinja b/php/ng/installed.jinja new file mode 100644 index 0000000..ce4236b --- /dev/null +++ b/php/ng/installed.jinja @@ -0,0 +1,6 @@ +# Template for installing packages. +{% from "php/ng/map.jinja" import php, sls_block with context %} +php_install_{{ state }}: + pkg.installed: + {{ sls_block(php.get(state).pkg_opts) }} + - name: {{ php.lookup.pkgs.get(state) }} diff --git a/php/ng/ldap.sls b/php/ng/ldap.sls new file mode 100644 index 0000000..f75346d --- /dev/null +++ b/php/ng/ldap.sls @@ -0,0 +1,2 @@ +{% set state = 'ldap' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/map.jinja b/php/ng/map.jinja new file mode 100644 index 0000000..8ae2f6c --- /dev/null +++ b/php/ng/map.jinja @@ -0,0 +1,336 @@ +{% 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': { + 'pkgs': { + 'php': 'php5', + 'apc': 'php-apc', + 'cgi': 'php5-cgi', + 'cli': 'php5-cli', + 'curl': 'php5-curl', + 'fpm': 'php5-fpm', + 'gd': 'php5-gd', + 'mbstring': 'php5', + 'mcrypt': 'php5-mcrypt', + 'memcache': 'php5-memcache', + 'memcached': 'php5-memcached', + 'mysql': 'php5-mysql', + 'mysqlnd': 'php5-mysqlnd', + 'pear': ' php-pear', + 'soap': ' php-soap', + 'xml': ' php5-xml', + 'imagick': 'php5-imagick', + 'suhosin': 'php5-suhosin', + 'imap': 'php5-imap', + 'adodb': 'php5-adodb', + 'pgsql': 'php5-pgsql', + 'ldap': 'php5-ldap', + }, + 'fpm': { + 'conf': '/etc/php5/fpm/php-fpm.conf', + 'ini': '/etc/php5/fpm/php.ini', + 'pools': '/etc/php5/fpm/pool.d', + 'service': 'php5-fpm', + 'defaults': odict([ + ('global', odict([ + ('pid', '/var/run/php5-fpm.pid'), + ('error_log', '/var/log/php5-fpm.log'), + ('include', '/etc/php5/fpm/pool.d/*.conf'), + ])), + ]), + }, + 'apache2_mod_php_ini': '/etc/php5/apache2/php.ini', + }, + 'RedHat': { + 'pkgs': { + 'php': 'php', + 'apc': 'php-pecl-apc', + 'cgi': 'php-cgi', + 'cli': 'php-cli', + 'curl': 'curl', + 'fpm': 'php-fpm', + 'gd': 'php-gd', + 'mbstring': 'php-mbstring', + 'mcrypt': 'php-mcrypt', + 'memcache': 'php-pecl-memcache', + 'memcached': 'php-pecl-memcached', + 'mysql': 'php-mysql', + 'mysqlnd': 'php-mysqlnd', + 'pear': ' php-pear', + 'soap': ' php-soap', + 'xml': ' php-xml', + 'imagick': 'php-imagick', + 'suhosin': 'php-suhosin', + 'imap': 'php-imap', + 'adodb': 'php-adodb', + 'pgsql': 'php-pgsql', + 'ldap': 'php-ldap', + }, + 'fpm': { + 'conf': '/etc/php-fpm.conf', + 'ini': '/etc/php.ini', + 'pools': '/etc/php-fpm.d', + 'service': 'php-fpm', + 'defaults': { + 'global': { + 'pid': '/var/run/php-fpm/php-fpm.pid', + 'error_log': '/var/log/php-fpm/error.log', + 'include': '/etc/php-fpm.d/*.conf', + }, + }, + }, + 'apache2_mod_php_ini': '/etc/php.ini', + }, + }), + 'adodb': { + 'pkg_opts': {}, + }, + 'apc': { + 'pkg_opts': {}, + }, + 'cgi': { + 'pkg_opts': {}, + }, + 'cli': { + 'pkg_opts': {}, + }, + 'curl': { + 'pkg_opts': {}, + }, + 'fpm': { + 'pkg_opts': {}, + 'service': { + 'enabled': True, + 'opts': {}, + }, + 'config': { + 'ini': { + 'opts': {}, + 'settings': {}, + }, + 'conf': { + 'opts': {}, + 'settings': {}, + }, + }, + 'pools': { + 'managed_opts': {}, + 'absent_opts': {}, + 'managed': {}, + }, + }, + 'gd': { + 'pkg_opts': {}, + }, + 'imagick': { + 'pkg_opts': {}, + }, + 'imap': { + 'pkg_opts': {}, + }, + 'ini': { + 'defaults': { + 'PHP': { + 'engine': 'On', + 'short_open_tag': 'Off', + 'asp_tags': 'Off', + 'precision': 14, + 'output_buffering': 4096, + 'zlib.output_compression': 'Off', + 'implicit_flush': 'Off', + 'serialize_precision': 17, + 'disable_functions': ['pcntl_alarm','pcntl_fork','pcntl_waitpid','pcntl_wait','pcntl_wifexited','pcntl_wifstopped','pcntl_wifsignaled', + 'pcntl_wexitstatus','pcntl_wtermsig','pcntl_wstopsig','pcntl_signal','pcntl_signal_dispatch','pcntl_get_last_error','pcntl_strerror', + 'pcntl_sigprocmask','pcntl_sigwaitinfo','pcntl_sigtimedwait','pcntl_exec','pcntl_getpriority','pcntl_setpriority'], + 'zend.enable_gc': 'On', + 'expose_php': 'On', + 'max_execution_time': 30, + 'max_input_time': 60, + 'max_input_nesting_level': 64, + 'max_input_vars': 1000, + 'memory_limit': '128M', + 'error_reporting': ['E_ALL', '~E_DEPRECATED', '~E_STRICT'], + 'display_errors': 'Off', + 'display_startup_errors': 'Off', + 'log_errors': 'On', + 'log_errors_max_len': 1024, + 'ignore_repeated_errors': 'Off', + 'ignore_repeated_source': 'Off', + 'report_memleaks': 'On', + 'track_errors': 'Off', + 'html_errors': 'On', + 'variables_order': 'GPCS', + 'request_order': 'GP', + 'register_argc_argv': 'Off', + 'auto_globals_jit': 'On', + 'post_max_size': '8M', + 'default_mimetype': '"text/html"', + 'enable_dl': 'Off', + 'file_uploads': 'On', + 'upload_max_filesize': '2M', + 'max_file_uploads': 20, + 'allow_url_fopen': 'On', + 'allow_url_include': 'Off', + 'default_socket_timeout': 60 + }, + 'CLI Server': { + 'cli_server.color': 'On' + }, + 'Date': { + 'date.timezone': 'America/New_York' + }, + 'Pdo_mysql': { + 'pdo_mysql.cache_size': 2000 + }, + 'mail function': { + 'SMTP': 'localhost', + 'mail.add_x_header': 'On' + }, + 'SQL': { + 'sql.safe_mode': 'Off' + }, + 'ODBC': { + 'odbc.allow_persistent': 'On', + 'odbc.check_persistent': 'On', + 'odbc.max_persistent': '-1', + 'odbc.max_links': '-1', + 'odbc.defaultlrl': 4096, + 'odbc.defaultbinmode': 1 + }, + 'Interbase': { + 'ibase.allow_persistent': 1, + 'ibase.max_persistent': -1, + 'ibase.max_links': -1, + 'ibase.timestampformat': '"%Y-%m-%d %H:%M:%S"', + 'ibase.dateformat': '"%Y-%m-%d"', + 'ibase.timeformat': '"%H:%M:%S"' + }, + 'MySQL': { + 'mysql.allow_local_infile': 'On', + 'mysql.allow_persistent': 'On', + 'mysql.cache_size': '2000', + 'mysql.max_persistent': -1, + 'mysql.max_links': -1, + 'mysql.connect_timeout': 60, + 'mysql.trace_mode': 'Off' + }, + 'MySQLi': { + 'mysqli.max_persistent': -1, + 'mysqli.allow_persistent': 'On', + 'mysqli.max_links': -1, + 'mysqli.cache_size': 2000, + 'mysqli.default_port': 3306, + 'mysqli.reconnect': 'Off' + }, + 'mysqlnd': { + 'mysqlnd.collect_statistics': 'On', + 'mysqlnd.collect_memory_statistics': 'Off' + }, + 'PostgreSQL': { + 'pgsql.allow_persistent': 'On', + 'pgsql.auto_reset_persistent': 'Off', + 'pgsql.max_persistent': -1, + 'pgsql.max_links': -1, + 'pgsql.ignore_notice': 0, + 'pgsql.log_notice': 0 + }, + 'Sybase-CT': { + 'sybct.allow_persistent': 'On', + 'sybct.max_persistent': -1, + 'sybct.max_links': -1, + 'sybct.min_server_severity': 10, + 'sybct.min_client_severity': 10 + }, + 'bcmath': { + 'bcmath.scale': 0 + }, + 'Session': { + 'session.save_handler': 'files', + 'session.use_strict_mode': 0, + 'session.use_cookies': 1, + 'session.use_only_cookies': 1, + 'session.name': 'PHPSESSID', + 'session.auto_start': 0, + 'session.cookie_lifetime': 0, + 'session.cookie_path': '/', + 'session.serialize_handler': 'php', + 'session.gc_probability': 0, + 'session.gc_divisor': 1000, + 'session.gc_maxlifetime': 1440, + 'session.bug_compat_42': 'Off', + 'session.bug_compat_warn': 'Off', + 'session.cache_limiter': 'nocache', + 'session.cache_expire': '180', + 'session.use_trans_sid': 0, + 'session.hash_function': 0, + 'session.hash_bits_per_character': 5, + 'url_rewriter.tags': '"a=href,area=href,frame=src,input=src,form=fakeentry"' + }, + 'MSSQL': { + 'mssql.allow_persistent': 'On', + 'mssql.max_persistent': -1, + 'mssql.max_links': -1, + 'mssql.min_error_severity': 10, + 'mssql.min_message_severity': 10, + 'mssql.compatibility_mode': 'Off', + 'mssql.secure_connection': 'Off' + }, + 'Tidy': { + 'tidy.clean_output': 'Off' + }, + 'soap': { + 'soap.wsdl_cache_enabled': 1, + 'soap.wsdl_cache_dir': '"/tmp"', + 'soap.wsdl_cache_ttl': 86400, + 'soap.wsdl_cache_limit': 5 + }, + 'ldap': { + 'ldap.max_links': -1 + }, + }, + }, + 'init': { + 'pkg_opts': {}, + }, + 'ldap': { + 'pkg_opts': {}, + }, + 'mbstring': { + 'pkg_opts': {}, + }, + 'mcrypt': { + 'pkg_opts': {}, + }, + 'memcache': { + 'pkg_opts': {}, + }, + 'memcached': { + 'pkg_opts': {}, + }, + 'mysql': { + 'pkg_opts': {}, + }, + 'mysqlnd': { + 'pkg_opts': {}, + }, + 'pear': { + 'pkg_opts': {}, + }, + 'pgsql': { + 'pkg_opts': {}, + }, + 'soap': { + 'pkg_opts': {}, + }, + 'suhosin': { + 'pkg_opts': {}, + }, + 'xml': { + 'pkg_opts': {}, + }, +}, merge=True) %} diff --git a/php/ng/map_ng.jinja b/php/ng/map_ng.jinja deleted file mode 100644 index eec87d2..0000000 --- a/php/ng/map_ng.jinja +++ /dev/null @@ -1,216 +0,0 @@ -{% set php = { - 'lookup': salt['grains.filter_by']({ - 'Debian': { - 'php_pkg': 'php5', - 'apc_pkg': 'php-apc', - 'cgi_pkg': 'php5-cgi', - 'cli_pkg': 'php5-cli', - 'curl_pkg': 'php5-curl', - 'fpm_pkg': 'php5-fpm', - 'gd_pkg': 'php5-gd', - 'mbstring_pkg': 'php5', - 'mcrypt_pkg': 'php5-mcrypt', - 'memcache_pkg': 'php5-memcache', - 'memcached_pkg': 'php5-memcached', - 'mysql_pkg': 'php5-mysql', - 'mysqlnd_pkg': 'php5-mysqlnd', - 'pear_pkg': ' php-pear', - 'soap_pkg': ' php-soap', - 'fpm_service': 'php5-fpm', - 'xml_pkg': ' php5-xml', - 'imagick_pkg': 'php5-imagick', - 'suhosin_pkg': 'php5-suhosin', - 'imap_pkg': 'php5-imap', - 'adodb_pkg': 'php5-adodb', - 'pgsql_pkg': 'php5-pgsql', - 'ldap_pkg': 'php5-ldap', - 'php_ini': '/etc/php5/apache2/php.ini', - }, - 'RedHat': { - 'php_pkg': 'php', - 'apc_pkg': 'php-pecl-apc', - 'cgi_pkg': 'php-cgi', - 'cli_pkg': 'php-cli', - 'curl_pkg': 'curl', - 'fpm_pkg': 'php-fpm', - 'gd_pkg': 'php-gd', - 'mbstring_pkg': 'php-mbstring', - 'mcrypt_pkg': 'php-mcrypt', - 'memcache_pkg': 'php-pecl-memcache', - 'memcached_pkg': 'php-pecl-memcached', - 'mysql_pkg': 'php-mysql', - 'mysqlnd_pkg': 'php-mysqlnd', - 'pear_pkg': ' php-pear', - 'soap_pkg': ' php-soap', - 'fpm_service': 'php-fpm', - 'xml_pkg': ' php-xml', - 'imagick_pkg': 'php-imagick', - 'suhosin_pkg': 'php-suhosin', - 'imap_pkg': 'php-imap', - 'adodb_pkg': 'php-adodb', - 'pgsql_pkg': 'php-pgsql', - 'ldap_pkg': 'php-ldap', - 'php_ini': '/etc/php.ini', - }, -}, merge=salt['pillar.get']('php:lookup')), - 'ini_settings': salt['pillar.get']('php:ini_settings', { - 'PHP': { - 'engine': 'On', - 'short_open_tag': 'Off', - 'asp_tags': 'Off', - 'precision': 14, - 'output_buffering': 4096, - 'zlib.output_compression': 'Off', - 'implicit_flush': 'Off', - 'serialize_precision': 17, - 'disable_functions': ['pcntl_alarm','pcntl_fork','pcntl_waitpid','pcntl_wait','pcntl_wifexited','pcntl_wifstopped','pcntl_wifsignaled', - 'pcntl_wexitstatus','pcntl_wtermsig','pcntl_wstopsig','pcntl_signal','pcntl_signal_dispatch','pcntl_get_last_error','pcntl_strerror', - 'pcntl_sigprocmask','pcntl_sigwaitinfo','pcntl_sigtimedwait','pcntl_exec','pcntl_getpriority','pcntl_setpriority'], - 'zend.enable_gc': 'On', - 'expose_php': 'On', - 'max_execution_time': 30, - 'max_input_time': 60, - 'max_input_nesting_level': 64, - 'max_input_vars': 1000, - 'memory_limit': '128M', - 'error_reporting': ['E_ALL', '~E_DEPRECATED', '~E_STRICT'], - 'display_errors': 'Off', - 'display_startup_errors': 'Off', - 'log_errors': 'On', - 'log_errors_max_len': 1024, - 'ignore_repeated_errors': 'Off', - 'ignore_repeated_source': 'Off', - 'report_memleaks': 'On', - 'track_errors': 'Off', - 'html_errors': 'On', - 'variables_order': 'GPCS', - 'request_order': 'GP', - 'register_argc_argv': 'Off', - 'auto_globals_jit': 'On', - 'post_max_size': '8M', - 'default_mimetype': '"text/html"', - 'enable_dl': 'Off', - 'file_uploads': 'On', - 'upload_max_filesize': '2M', - 'max_file_uploads': 20, - 'allow_url_fopen': 'On', - 'allow_url_include': 'Off', - 'default_socket_timeout': 60 - }, - 'CLI Server': { - 'cli_server.color': 'On' - }, - 'Date': { - 'date.timezone': 'America/New_York' - }, - 'Pdo_mysql': { - 'pdo_mysql.cache_size': 2000 - }, - 'mail function': { - 'SMTP': 'localhost', - 'mail.add_x_header': 'On' - }, - 'SQL': { - 'sql.safe_mode': 'Off' - }, - 'ODBC': { - 'odbc.allow_persistent': 'On', - 'odbc.check_persistent': 'On', - 'odbc.max_persistent': '-1', - 'odbc.max_links': '-1', - 'odbc.defaultlrl': 4096, - 'odbc.defaultbinmode': 1 - }, - 'Interbase': { - 'ibase.allow_persistent': 1, - 'ibase.max_persistent': -1, - 'ibase.max_links': -1, - 'ibase.timestampformat': '"%Y-%m-%d %H:%M:%S"', - 'ibase.dateformat': '"%Y-%m-%d"', - 'ibase.timeformat': '"%H:%M:%S"' - }, - 'MySQL': { - 'mysql.allow_local_infile': 'On', - 'mysql.allow_persistent': 'On', - 'mysql.cache_size': '2000', - 'mysql.max_persistent': -1, - 'mysql.max_links': -1, - 'mysql.connect_timeout': 60, - 'mysql.trace_mode': 'Off' - }, - 'MySQLi': { - 'mysqli.max_persistent': -1, - 'mysqli.allow_persistent': 'On', - 'mysqli.max_links': -1, - 'mysqli.cache_size': 2000, - 'mysqli.default_port': 3306, - 'mysqli.reconnect': 'Off' - }, - 'mysqlnd': { - 'mysqlnd.collect_statistics': 'On', - 'mysqlnd.collect_memory_statistics': 'Off' - }, - 'PostgreSQL': { - 'pgsql.allow_persistent': 'On', - 'pgsql.auto_reset_persistent': 'Off', - 'pgsql.max_persistent': -1, - 'pgsql.max_links': -1, - 'pgsql.ignore_notice': 0, - 'pgsql.log_notice': 0 - }, - 'Sybase-CT': { - 'sybct.allow_persistent': 'On', - 'sybct.max_persistent': -1, - 'sybct.max_links': -1, - 'sybct.min_server_severity': 10, - 'sybct.min_client_severity': 10 - }, - 'bcmath': { - 'bcmath.scale': 0 - }, - 'Session': { - 'session.save_handler': 'files', - 'session.use_strict_mode': 0, - 'session.use_cookies': 1, - 'session.use_only_cookies': 1, - 'session.name': 'PHPSESSID', - 'session.auto_start': 0, - 'session.cookie_lifetime': 0, - 'session.cookie_path': '/', - 'session.serialize_handler': 'php', - 'session.gc_probability': 0, - 'session.gc_divisor': 1000, - 'session.gc_maxlifetime': 1440, - 'session.bug_compat_42': 'Off', - 'session.bug_compat_warn': 'Off', - 'session.cache_limiter': 'nocache', - 'session.cache_expire': '180', - 'session.use_trans_sid': 0, - 'session.hash_function': 0, - 'session.hash_bits_per_character': 5, - 'url_rewriter.tags': '"a=href,area=href,frame=src,input=src,form=fakeentry"' - }, - 'MSSQL': { - 'mssql.allow_persistent': 'On', - 'mssql.max_persistent': -1, - 'mssql.max_links': -1, - 'mssql.min_error_severity': 10, - 'mssql.min_message_severity': 10, - 'mssql.compatibility_mode': 'Off', - 'mssql.secure_connection': 'Off' - }, - 'Tidy': { - 'tidy.clean_output': 'Off' - }, - 'soap': { - 'soap.wsdl_cache_enabled': 1, - 'soap.wsdl_cache_dir': '"/tmp"', - 'soap.wsdl_cache_ttl': 86400, - 'soap.wsdl_cache_limit': 5 - }, - 'ldap': { - 'ldap.max_links': -1 - } - }, merge=True) - -}%} diff --git a/php/ng/mbstring.sls b/php/ng/mbstring.sls new file mode 100644 index 0000000..f8dcbca --- /dev/null +++ b/php/ng/mbstring.sls @@ -0,0 +1,2 @@ +{% set state = 'mbstring' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/mcrypt.sls b/php/ng/mcrypt.sls new file mode 100644 index 0000000..e69fe13 --- /dev/null +++ b/php/ng/mcrypt.sls @@ -0,0 +1,2 @@ +{% set state = 'mcrypt' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/memcache.sls b/php/ng/memcache.sls new file mode 100644 index 0000000..f140102 --- /dev/null +++ b/php/ng/memcache.sls @@ -0,0 +1,2 @@ +{% set state = 'memcache' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/memcached.sls b/php/ng/memcached.sls new file mode 100644 index 0000000..9509c25 --- /dev/null +++ b/php/ng/memcached.sls @@ -0,0 +1,2 @@ +{% set state = 'memcached' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/mysql.sls b/php/ng/mysql.sls new file mode 100644 index 0000000..ad0cfe7 --- /dev/null +++ b/php/ng/mysql.sls @@ -0,0 +1,2 @@ +{% set state = 'mysql' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/mysqlnd.sls b/php/ng/mysqlnd.sls new file mode 100644 index 0000000..90af175 --- /dev/null +++ b/php/ng/mysqlnd.sls @@ -0,0 +1,2 @@ +{% set state = 'mysqld' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/pear.sls b/php/ng/pear.sls new file mode 100644 index 0000000..560d25a --- /dev/null +++ b/php/ng/pear.sls @@ -0,0 +1,2 @@ +{% set state = 'pear' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/pgsql.sls b/php/ng/pgsql.sls new file mode 100644 index 0000000..859e1e9 --- /dev/null +++ b/php/ng/pgsql.sls @@ -0,0 +1,2 @@ +{% set state = 'pgsql' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/soap.sls b/php/ng/soap.sls new file mode 100644 index 0000000..28f2344 --- /dev/null +++ b/php/ng/soap.sls @@ -0,0 +1,2 @@ +{% set state = 'soap' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/suhosin.sls b/php/ng/suhosin.sls new file mode 100644 index 0000000..9099199 --- /dev/null +++ b/php/ng/suhosin.sls @@ -0,0 +1,2 @@ +{% set state = 'suhosin' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/xml.sls b/php/ng/xml.sls new file mode 100644 index 0000000..70c974e --- /dev/null +++ b/php/ng/xml.sls @@ -0,0 +1,2 @@ +{% set state = 'xml' %} +{% include "php/ng/installed.jinja" %} From 5b18a9a4b72e8cd6bfbcb6e0141fcbdba1d971dd Mon Sep 17 00:00:00 2001 From: Chad Heuschober Date: Tue, 20 May 2014 22:07:16 -0400 Subject: [PATCH 03/11] Cleaned up the installed package bit. --- php/ng/installed.jinja | 6 ++-- php/ng/map.jinja | 65 +----------------------------------------- 2 files changed, 5 insertions(+), 66 deletions(-) diff --git a/php/ng/installed.jinja b/php/ng/installed.jinja index ce4236b..3717475 100644 --- a/php/ng/installed.jinja +++ b/php/ng/installed.jinja @@ -1,6 +1,8 @@ # Template for installing packages. {% from "php/ng/map.jinja" import php, sls_block with context %} +{% set opts = php.installed.get(state, {}) %} + php_install_{{ state }}: pkg.installed: - {{ sls_block(php.get(state).pkg_opts) }} - - name: {{ php.lookup.pkgs.get(state) }} + {{ sls_block(opts) }} + - name: {{ php.lookup.pkgs.get(state) }} diff --git a/php/ng/map.jinja b/php/ng/map.jinja index 8ae2f6c..e91c1dd 100644 --- a/php/ng/map.jinja +++ b/php/ng/map.jinja @@ -87,23 +87,8 @@ 'apache2_mod_php_ini': '/etc/php.ini', }, }), - 'adodb': { - 'pkg_opts': {}, - }, - 'apc': { - 'pkg_opts': {}, - }, - 'cgi': { - 'pkg_opts': {}, - }, - 'cli': { - 'pkg_opts': {}, - }, - 'curl': { - 'pkg_opts': {}, - }, + 'installed': {}, 'fpm': { - 'pkg_opts': {}, 'service': { 'enabled': True, 'opts': {}, @@ -124,15 +109,6 @@ 'managed': {}, }, }, - 'gd': { - 'pkg_opts': {}, - }, - 'imagick': { - 'pkg_opts': {}, - }, - 'imap': { - 'pkg_opts': {}, - }, 'ini': { 'defaults': { 'PHP': { @@ -294,43 +270,4 @@ }, }, }, - 'init': { - 'pkg_opts': {}, - }, - 'ldap': { - 'pkg_opts': {}, - }, - 'mbstring': { - 'pkg_opts': {}, - }, - 'mcrypt': { - 'pkg_opts': {}, - }, - 'memcache': { - 'pkg_opts': {}, - }, - 'memcached': { - 'pkg_opts': {}, - }, - 'mysql': { - 'pkg_opts': {}, - }, - 'mysqlnd': { - 'pkg_opts': {}, - }, - 'pear': { - 'pkg_opts': {}, - }, - 'pgsql': { - 'pkg_opts': {}, - }, - 'soap': { - 'pkg_opts': {}, - }, - 'suhosin': { - 'pkg_opts': {}, - }, - 'xml': { - 'pkg_opts': {}, - }, }, merge=True) %} From 9c5ef0395b1298f17aa654ddda12068cc8068ae4 Mon Sep 17 00:00:00 2001 From: Chad Heuschober Date: Wed, 21 May 2014 00:46:56 -0400 Subject: [PATCH 04/11] Tightened up some ng requirements. --- php/ng/fpm/init.sls | 3 +++ php/ng/fpm/pools.sls | 15 +++++++++++---- php/ng/fpm/service.sls | 1 - 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/php/ng/fpm/init.sls b/php/ng/fpm/init.sls index 298e969..dfa63a8 100644 --- a/php/ng/fpm/init.sls +++ b/php/ng/fpm/init.sls @@ -13,3 +13,6 @@ extend: - watch: - file: php_fpm_ini_config - file: php_fpm_conf_config + - require: + - file: php_fpm_ini_config + - file: php_fpm_conf_config diff --git a/php/ng/fpm/pools.sls b/php/ng/fpm/pools.sls index c41f45c..5c3779e 100644 --- a/php/ng/fpm/pools.sls +++ b/php/ng/fpm/pools.sls @@ -3,14 +3,21 @@ {% from 'php/ng/fpm/pools_config.sls' import pool_states with context %} {% from 'php/ng/fpm/service.sls' import service_function with context %} +{% macro file_requisites(states) %} + {%- for state in states %} + - file: {{ state }} + {%- endfor -%} +{% endmacro %} + include: - php.ng.fpm.service - php.ng.fpm.pools_config + extend: php_fpm_service: - service.{{ service_function }}: + service: - watch: - {%- for pool in pool_states %} - - file: {{ pool }} - {% endfor -%} + {{ file_requisites(pool_states) }} + - require: + {{ file_requisites(pool_states) }} diff --git a/php/ng/fpm/service.sls b/php/ng/fpm/service.sls index b729ebb..45cb1f5 100644 --- a/php/ng/fpm/service.sls +++ b/php/ng/fpm/service.sls @@ -14,4 +14,3 @@ php_fpm_service: - sls: php.ng.fpm.install - watch: - pkg: php_install_fpm - From 0b65d5aaea61ea0858d02d280c916a6a6a617c2f Mon Sep 17 00:00:00 2001 From: Chad Heuschober Date: Wed, 21 May 2014 00:48:52 -0400 Subject: [PATCH 05/11] Tightened up some ng requirements. --- php/ng/fpm/pools.sls | 2 -- 1 file changed, 2 deletions(-) diff --git a/php/ng/fpm/pools.sls b/php/ng/fpm/pools.sls index 5c3779e..459f4c8 100644 --- a/php/ng/fpm/pools.sls +++ b/php/ng/fpm/pools.sls @@ -1,7 +1,6 @@ # 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/fpm/service.sls' import service_function with context %} {% macro file_requisites(states) %} {%- for state in states %} @@ -13,7 +12,6 @@ include: - php.ng.fpm.service - php.ng.fpm.pools_config - extend: php_fpm_service: service: From c2435a397f7c0d4e50f714d456e7779682f8d814 Mon Sep 17 00:00:00 2001 From: Chad Heuschober Date: Thu, 22 May 2014 14:38:27 -0400 Subject: [PATCH 06/11] 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 --- php/ng/files/php.ini | 39 +++++++++++---------- php/ng/fpm/config.sls | 7 ++-- php/ng/fpm/pools.sls | 5 +-- php/ng/fpm/pools_config.sls | 5 +-- php/ng/fpm/service.sls | 4 ++- php/ng/ini.sls | 5 +-- php/ng/installed.jinja | 4 ++- php/ng/macro.jinja | 68 +++++++++++++++++++++++++++++++++++++ php/ng/map.jinja | 6 ---- 9 files changed, 108 insertions(+), 35 deletions(-) create mode 100644 php/ng/macro.jinja diff --git a/php/ng/files/php.ini b/php/ng/files/php.ini index 20ae67e..d3f1a77 100644 --- a/php/ng/files/php.ini +++ b/php/ng/files/php.ini @@ -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) }} diff --git a/php/ng/fpm/config.sls b/php/ng/fpm/config.sls index fd49961..1f24472 100644 --- a/php/ng/fpm/config.sls +++ b/php/ng/fpm/config.sls @@ -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) }} diff --git a/php/ng/fpm/pools.sls b/php/ng/fpm/pools.sls index 459f4c8..79bb0b4 100644 --- a/php/ng/fpm/pools.sls +++ b/php/ng/fpm/pools.sls @@ -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 %} diff --git a/php/ng/fpm/pools_config.sls b/php/ng/fpm/pools_config.sls index 61f0ba4..924b461 100644 --- a/php/ng/fpm/pools_config.sls +++ b/php/ng/fpm/pools_config.sls @@ -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 }} diff --git a/php/ng/fpm/service.sls b/php/ng/fpm/service.sls index 45cb1f5..aa8cd2c 100644 --- a/php/ng/fpm/service.sls +++ b/php/ng/fpm/service.sls @@ -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: diff --git a/php/ng/ini.sls b/php/ng/ini.sls index 2730a70..cae024f 100644 --- a/php/ng/ini.sls +++ b/php/ng/ini.sls @@ -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) }} diff --git a/php/ng/installed.jinja b/php/ng/installed.jinja index 3717475..0f9f360 100644 --- a/php/ng/installed.jinja +++ b/php/ng/installed.jinja @@ -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 }}: diff --git a/php/ng/macro.jinja b/php/ng/macro.jinja new file mode 100644 index 0000000..4dfb717 --- /dev/null +++ b/php/ng/macro.jinja @@ -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 -%} diff --git a/php/ng/map.jinja b/php/ng/map.jinja index e91c1dd..48b5e6e 100644 --- a/php/ng/map.jinja +++ b/php/ng/map.jinja @@ -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': { From 116f3fae701736399464b67f5087304c2226685d Mon Sep 17 00:00:00 2001 From: Chad Heuschober Date: Fri, 6 Jun 2014 13:14:44 -0400 Subject: [PATCH 07/11] Rewrote ini and cli.ini handling --- CHANGELOG.rst | 13 ++ README.rst | 193 ++++++++++++++++++++++++++-- VERSION | 1 + php/ng/cli/ini.sls | 9 ++ php/ng/cli/init.sls | 11 ++ php/ng/{cli.sls => cli/install.sls} | 0 php/ng/files/php.ini | 2 +- php/ng/fpm/config.sls | 18 +-- php/ng/fpm/init.sls | 7 +- php/ng/ini.jinja | 12 ++ php/ng/ini.sls | 13 -- php/ng/installed.jinja | 23 +++- php/ng/json.sls | 2 + php/ng/macro.jinja | 41 ------ php/ng/map.jinja | 18 ++- pillar.example | 39 ++++++ 16 files changed, 309 insertions(+), 93 deletions(-) create mode 100644 CHANGELOG.rst create mode 100644 VERSION create mode 100644 php/ng/cli/ini.sls create mode 100644 php/ng/cli/init.sls rename php/ng/{cli.sls => cli/install.sls} (100%) create mode 100644 php/ng/ini.jinja delete mode 100644 php/ng/ini.sls create mode 100644 php/ng/json.sls diff --git a/CHANGELOG.rst b/CHANGELOG.rst new file mode 100644 index 0000000..8508766 --- /dev/null +++ b/CHANGELOG.rst @@ -0,0 +1,13 @@ +=========== +php-formula +=========== + +0.2.0 +----- + +- Added .ng states + +0.1.0 +----- + +- Initial version diff --git a/README.rst b/README.rst index 8fb2a4d..0391b76 100644 --- a/README.rst +++ b/README.rst @@ -26,17 +26,17 @@ Installs the php package. Installs the php-apc package. ``php.adodb`` ------------- +------------- Installs the php-adodb package. ``php.cgi`` ------------- +----------- Installs the php-cgi package. ``php.cli`` ------------- +----------- Installs the php-cli package. @@ -59,7 +59,7 @@ Installs the php-gd package. ``php.imagick`` ------------- +--------------- Installs the php-imagick package. @@ -79,7 +79,7 @@ Installs the php-json package. Installs the php-ldap package. ``php.mbstring`` ---------------- +---------------- Installs the php-mbstring package. @@ -90,12 +90,12 @@ Installs the php-mcrypt package. ``php.memcache`` ------------- +---------------- Installs the php-memcache package. ``php.memcached`` ------------- +----------------- Installs the php-memcached package. @@ -105,7 +105,7 @@ Installs the php-memcached package. Installs the php-mysql package. ``php.mysqlnd`` ------------- +--------------- Installs the php-mysqlnd package. @@ -115,7 +115,7 @@ Installs the php-mysqlnd package. Installs the php-pear package. ``php.pgsql`` ------------- +------------- Installs the php-pgsql package. @@ -125,11 +125,182 @@ Installs the php-pgsql package. Installs the php-soap package. ``php.suhosin`` ------------- +--------------- Installs the php-suhosin package. ``php.xml`` ------------- +----------- Installs the php-xml package. + +Next-generation, alternate approach +=================================== + +The following states provide an alternate approach to managing PHP and FPM +pools, as well as code organization. Please provide feedback by filing issues, +discussing in ``#salt`` in Freenode and the mailing list as normal. + +**Note:** php.ng states require the merge parameter of salt.modules.pillar.get(), +first available in the Helium release. + +.. contents:: + :local: + +``php.ng`` +---------- + +Installs the php package. + +``php.ng.adodb`` +---------------- + +Installs the php-adodb package. + +``php.ng.apc`` +-------------- + +Installs the php-apc package. + +``php.ng.cgi`` +-------------- + +Installs the php-cgi package. + +``php.ng.cli`` +-------------- + +Meta-state that combines `php.ng.cli.install`_ and `php.ng.cli.ini`_. + +``php.ng.cli.install`` +---------------------- + +Installs the php-cli package. + +``php.ng.cli.ini`` +------------------ + +Manages the php-cli ini file. + +``php.ng.curl`` +--------------- + +Installs the php5-curl package on Debian, and ensures that curl itself is +installed for RedHat systems, this is due to the curl libs being provided by +php-common, which will get installed with the main php package. + +``php.ng.fpm`` +-------------- + +Meta-state that combines all php.ng.fpm states. + +``php.ng.fpm.config`` +--------------------- + +Manages the (non-pool) php-fpm config files. + + +``php.ng.fpm.install`` +---------------------- + +Installs the php-fpm package. + + +``php.ng.fpm.pools`` +-------------------- + +Meta-state that combines `php.ng.fpm.service`_ and `php.ng.fpm.pools_config`_ + + +``php.ng.fpm.pools_config`` +--------------------------- + +Manages php-fpm pool config files. + + +``php.ng.fpm.service`` +---------------------- + +Manages the php-fpm service. + +``php.ng.gd`` +------------- + +Installs the php-gd package. + + +``php.ng.imagick`` +------------------ + +Installs the php-imagick package. + +``php.ng.imap`` +--------------- + +Installs the php-imap package. + +``php.ng.json`` +--------------- + +Installs the php-json package. + +``php.ng.ldap`` +--------------- + +Installs the php-ldap package. + +``php.ng.mbstring`` +------------------- + +Installs the php-mbstring package. + +``php.ng.mcrypt`` +----------------- + +Installs the php-mcrypt package. + + +``php.ng.memcache`` +------------------- + +Installs the php-memcache package. + +``php.ng.memcached`` +-------------------- + +Installs the php-memcached package. + +``php.ng.mysql`` +---------------- + +Installs the php-mysql package. + +``php.ng.mysqlnd`` +------------------ + +Installs the php-mysqlnd package. + +``php.ng.pear`` +--------------- + +Installs the php-pear package. + +``php.ng.pgsql`` +---------------- + +Installs the php-pgsql package. + +``php.ng.soap`` +--------------- + +Installs the php-soap package. + +``php.ng.suhosin`` +------------------ + +Installs the php-suhosin package. + +``php.ng.xml`` +-------------- + +Installs the php-xml package. \ No newline at end of file diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..81340c7 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.4 diff --git a/php/ng/cli/ini.sls b/php/ng/cli/ini.sls new file mode 100644 index 0000000..b6256e4 --- /dev/null +++ b/php/ng/cli/ini.sls @@ -0,0 +1,9 @@ +# Manages the php cli main ini file +{% from 'php/ng/map.jinja' import php with context %} +{% from "php/ng/ini.jinja" import php_ini %} + +{% set settings = php.ini.defaults %} +{% do settings.update(php.cli.ini.settings) %} + +php_cli_ini: + {{ php_ini(php.lookup.cli.ini, php.cli.ini.opts, settings) }} diff --git a/php/ng/cli/init.sls b/php/ng/cli/init.sls new file mode 100644 index 0000000..06bc3e9 --- /dev/null +++ b/php/ng/cli/init.sls @@ -0,0 +1,11 @@ +# Installs php-cli and manages the associated php.ini + +include: + - php.ng.cli.install + - php.ng.cli.ini + +extend: + php_cli_ini: + file: + - require: + - sls: php.ng.cli.install diff --git a/php/ng/cli.sls b/php/ng/cli/install.sls similarity index 100% rename from php/ng/cli.sls rename to php/ng/cli/install.sls diff --git a/php/ng/files/php.ini b/php/ng/files/php.ini index d3f1a77..d16d374 100644 --- a/php/ng/files/php.ini +++ b/php/ng/files/php.ini @@ -27,5 +27,5 @@ ; ; **** DO NOT EDIT THIS FILE **** ; -; This file is managed by Salt +; This file is managed by Salt via {{ source }} {{ php_block(config) }} diff --git a/php/ng/fpm/config.sls b/php/ng/fpm/config.sls index 1f24472..844b5ba 100644 --- a/php/ng/fpm/config.sls +++ b/php/ng/fpm/config.sls @@ -1,6 +1,6 @@ # Manages the php-fpm main ini file {% from 'php/ng/map.jinja' import php with context %} -{% from "php/ng/macro.jinja" import sls_block, serialize %} +{% from "php/ng/ini.jinja" import php_ini %} {% set ini_settings = php.ini.defaults %} {% do ini_settings.update(php.fpm.config.ini.settings) %} @@ -9,19 +9,7 @@ {% do conf_settings.update(php.fpm.config.conf.settings) %} php_fpm_ini_config: - file.managed: - {{ sls_block(php.fpm.config.ini.opts) }} - - name: {{ php.lookup.fpm.ini }} - - source: salt://php/ng/files/php.ini - - template: jinja - - context: - config: {{ serialize(ini_settings) }} + {{ php_ini(php.lookup.fpm.ini, php.fpm.config.ini.opts, ini_settings) }} php_fpm_conf_config: - file.managed: - {{ sls_block(php.fpm.config.conf.opts) }} - - name: {{ php.lookup.fpm.conf }} - - source: salt://php/ng/files/php.ini - - template: jinja - - context: - config: {{ serialize(conf_settings) }} + {{ php_ini(php.lookup.fpm.conf, php.fpm.config.conf.opts, conf_settings) }} diff --git a/php/ng/fpm/init.sls b/php/ng/fpm/init.sls index dfa63a8..2aa9ecb 100644 --- a/php/ng/fpm/init.sls +++ b/php/ng/fpm/init.sls @@ -1,6 +1,4 @@ -# php.ng.fpm -# -# Meta-state to fully install php. +# Meta-state to fully install php.fpm include: - php.ng.fpm.config @@ -14,5 +12,4 @@ extend: - file: php_fpm_ini_config - file: php_fpm_conf_config - require: - - file: php_fpm_ini_config - - file: php_fpm_conf_config + - sls: php.ng.fpm.config diff --git a/php/ng/ini.jinja b/php/ng/ini.jinja new file mode 100644 index 0000000..eb95003 --- /dev/null +++ b/php/ng/ini.jinja @@ -0,0 +1,12 @@ +# php.ini management macro. +{% from "php/ng/macro.jinja" import sls_block, serialize %} + +{% macro php_ini(filename, opts={}, settings={}) %} + file.managed: + {{ sls_block(opts) }} + - name: {{ filename }} + - source: salt://php/ng/files/php.ini + - template: jinja + - context: + config: {{ serialize(settings) }} +{%- endmacro -%} diff --git a/php/ng/ini.sls b/php/ng/ini.sls deleted file mode 100644 index cae024f..0000000 --- a/php/ng/ini.sls +++ /dev/null @@ -1,13 +0,0 @@ -# php.ng.ini.sls -# -# Generic php.ini management state. -{% from "php/ng/map.jinja" import php with context %} -{% from "php/ng/macro.jinja" import sls_block, serialize %} - -php_ini: - file.managed: - {{ sls_block(php.ini.file_opts) }} - - source: salt://php/ng/files/php.ini - - template: jinja - - context: - config: {{ serialize(php.ini.settings) }} diff --git a/php/ng/installed.jinja b/php/ng/installed.jinja index 0f9f360..9bf0c81 100644 --- a/php/ng/installed.jinja +++ b/php/ng/installed.jinja @@ -2,9 +2,26 @@ {% from "php/ng/map.jinja" import php with context %} {% from "php/ng/macro.jinja" import sls_block %} -{% set opts = php.installed.get(state, {}) %} + +{% pkginfo = php.lookup.pkgs.get(state) %} + +{%- if pkginfo is mapping -%} + {%- for pkg, opts in pkginfo.items() -%} + +php_install_{{ state }}_{{ pkg }}: + pkg.installed: + {{ sls_block(opts) }} + - name: {{ state }} + + {%- endfor -%} +{%- else -%} + {%- if pkginfo is not sequence or is string -%} + {% set pkginfo = [pkginfo] %} + {%- endif -%} php_install_{{ state }}: pkg.installed: - {{ sls_block(opts) }} - - name: {{ php.lookup.pkgs.get(state) }} + - name: {{ state }} + - pkgs: {{ php.lookup.pkgs.get(state)|json() }} + +{%- endif -%} diff --git a/php/ng/json.sls b/php/ng/json.sls new file mode 100644 index 0000000..1f9d6d8 --- /dev/null +++ b/php/ng/json.sls @@ -0,0 +1,2 @@ +{% set state = 'json' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/macro.jinja b/php/ng/macro.jinja index 4dfb717..b13fbf4 100644 --- a/php/ng/macro.jinja +++ b/php/ng/macro.jinja @@ -25,44 +25,3 @@ {{ 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 -%} diff --git a/php/ng/map.jinja b/php/ng/map.jinja index 48b5e6e..8622ae4 100644 --- a/php/ng/map.jinja +++ b/php/ng/map.jinja @@ -24,6 +24,7 @@ 'adodb': 'php5-adodb', 'pgsql': 'php5-pgsql', 'ldap': 'php5-ldap', + 'json': 'php5-json', }, 'fpm': { 'conf': '/etc/php5/fpm/php-fpm.conf', @@ -38,7 +39,9 @@ ])), ]), }, - 'apache2_mod_php_ini': '/etc/php5/apache2/php.ini', + 'cli': { + 'ini': '/etc/php5/cli/php.ini', + }, }, 'RedHat': { 'pkgs': { @@ -46,7 +49,7 @@ 'apc': 'php-pecl-apc', 'cgi': 'php-cgi', 'cli': 'php-cli', - 'curl': 'curl', + 'curl': ['php-common', 'curl'], 'fpm': 'php-fpm', 'gd': 'php-gd', 'mbstring': 'php-mbstring', @@ -64,6 +67,7 @@ 'adodb': 'php-adodb', 'pgsql': 'php-pgsql', 'ldap': 'php-ldap', + 'json': 'php-common', }, 'fpm': { 'conf': '/etc/php-fpm.conf', @@ -78,10 +82,11 @@ }, }, }, - 'apache2_mod_php_ini': '/etc/php.ini', + 'cli': { + 'ini': '/etc/php.ini', + }, }, }), - 'installed': {}, 'fpm': { 'service': { 'enabled': True, @@ -103,6 +108,11 @@ 'managed': {}, }, }, + 'cli': { + 'ini': + 'opts': {}, + 'settings': {}, + }, 'ini': { 'defaults': { 'PHP': { diff --git a/pillar.example b/pillar.example index e69de29..58c4015 100644 --- a/pillar.example +++ b/pillar.example @@ -0,0 +1,39 @@ +## php.ng pillar examples + +php: + ng: + # this section contains mostly grain filtered data, while overrides + # are possible in the pillar for unique cases, if your OS is not + # represented, please consider adding it to the map.jinja for + # upstream inclusion + lookup: + + # package definitions, these can lists, strings, or dictionaries + pkgs: + memcached: php5-memcached + # ensures both will be installed + curl: + - php-common + - curl + # a dictionary can be used in more complex cases where you want + # to pass forward special arguments to the pkg.installed call + cli: + php-cli: + fromrepo: my-specialrepo + php-common: + fromrepo: my-specialrepo + + # php-fpm os-specific settings + fpm: + # the main php-fpm config file + conf: /etc/php5/fpm/php-fpm.conf + # the php-fpm php.ini + ini: /etc/php5/fpm/php.ini + # the location where pools are stored + pools: /etc/php5/fpm/pool.d + # the name of the php-fpm service + service: php5-fpm + # the default content of the php5-fpm main config file + defaults: + global: + pid: /var/run/php5-fpm.pid From b8278ba19aac40311a64cf3f1b5aa632435c7078 Mon Sep 17 00:00:00 2001 From: Chad Heuschober Date: Fri, 6 Jun 2014 13:20:03 -0400 Subject: [PATCH 08/11] Fixed mixxing set in installed.jinja --- php/ng/installed.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/ng/installed.jinja b/php/ng/installed.jinja index 9bf0c81..eb172e6 100644 --- a/php/ng/installed.jinja +++ b/php/ng/installed.jinja @@ -3,7 +3,7 @@ {% from "php/ng/macro.jinja" import sls_block %} -{% pkginfo = php.lookup.pkgs.get(state) %} +{% set pkginfo = php.lookup.pkgs.get(state) %} {%- if pkginfo is mapping -%} {%- for pkg, opts in pkginfo.items() -%} From 0a8b0ceaf1e2c7e75a81cff2455da1faaec67033 Mon Sep 17 00:00:00 2001 From: Chad Heuschober Date: Fri, 6 Jun 2014 13:21:22 -0400 Subject: [PATCH 09/11] Fixed broken test ininstalled.jinja --- php/ng/installed.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/ng/installed.jinja b/php/ng/installed.jinja index eb172e6..5919ed5 100644 --- a/php/ng/installed.jinja +++ b/php/ng/installed.jinja @@ -15,7 +15,7 @@ php_install_{{ state }}_{{ pkg }}: {%- endfor -%} {%- else -%} - {%- if pkginfo is not sequence or is string -%} + {%- if pkginfo is not sequence or pkginfo is string -%} {% set pkginfo = [pkginfo] %} {%- endif -%} From ef19addb98ea8bd1da97efaef6e2c74ee590559a Mon Sep 17 00:00:00 2001 From: Chad Heuschober Date: Fri, 6 Jun 2014 14:53:36 -0400 Subject: [PATCH 10/11] Cleaned up pools. --- php/ng/fpm/pools_config.sls | 4 +- php/ng/installed.jinja | 35 ++++++++------ php/ng/map.jinja | 9 ++-- pillar.example | 94 ++++++++++++++++++++++++++++++++----- 4 files changed, 108 insertions(+), 34 deletions(-) diff --git a/php/ng/fpm/pools_config.sls b/php/ng/fpm/pools_config.sls index 924b461..fe255c5 100644 --- a/php/ng/fpm/pools_config.sls +++ b/php/ng/fpm/pools_config.sls @@ -9,14 +9,14 @@ {% set pool_states = [] %} -{% for pool, config in php.fpm.pools.managed.items() %} +{% for pool, config in php.fpm.pools.items() %} {% set state = 'php_fpm_pool_conf_' ~ loop.index0 %} {% set fpath = path_join(pool, php.lookup.fpm.pools) %} {{ state }}: {% if config.enabled %} file.managed: - {{ sls_block(php.fpm.pools.managed_opts) }} + {{ sls_block(config.opts) }} - name: {{ fpath }} - source: salt://php/ng/files/php.ini - template: jinja diff --git a/php/ng/installed.jinja b/php/ng/installed.jinja index 5919ed5..249423c 100644 --- a/php/ng/installed.jinja +++ b/php/ng/installed.jinja @@ -5,23 +5,30 @@ {% set pkginfo = php.lookup.pkgs.get(state) %} -{%- if pkginfo is mapping -%} - {%- for pkg, opts in pkginfo.items() -%} +{% set pkgs = [] %} +{% set specials = [] %} -php_install_{{ state }}_{{ pkg }}: - pkg.installed: - {{ sls_block(opts) }} - - name: {{ state }} - - {%- endfor -%} -{%- else -%} - {%- if pkginfo is not sequence or pkginfo is string -%} - {% set pkginfo = [pkginfo] %} - {%- endif -%} +{% if pkginfo is iterable and pkginfo is not string %} + {% for pkg in pkginfo %} + {% if pkg is mapping %} + {% do specials.append(pkg) %} + {% else %} + {% do pkgs.append(pkg) %} + {% endif %} + {% endfor %} +{% else %} + {% do pkgs.append(pkginfo) %} +{% endif %} php_install_{{ state }}: pkg.installed: - name: {{ state }} - - pkgs: {{ php.lookup.pkgs.get(state)|json() }} + - pkgs: {{ pkgs|json() }} -{%- endif -%} +{% for pkg in specials %} + +php_install_{{ state }}_{{ pkg.get('name') }}: + pkg.installed: + {{ sls_block(pkg) }} + +{% endfor %} diff --git a/php/ng/map.jinja b/php/ng/map.jinja index 8622ae4..492e8c6 100644 --- a/php/ng/map.jinja +++ b/php/ng/map.jinja @@ -102,16 +102,13 @@ 'settings': {}, }, }, - 'pools': { - 'managed_opts': {}, - 'absent_opts': {}, - 'managed': {}, - }, + 'pools': {}, }, 'cli': { - 'ini': + 'ini': { 'opts': {}, 'settings': {}, + } }, 'ini': { 'defaults': { diff --git a/pillar.example b/pillar.example index 58c4015..7bd42c8 100644 --- a/pillar.example +++ b/pillar.example @@ -8,7 +8,8 @@ php: # upstream inclusion lookup: - # package definitions, these can lists, strings, or dictionaries + # package definitions, these can strings, lists of strings, or + # lists of dictionaries pkgs: memcached: php5-memcached # ensures both will be installed @@ -17,23 +18,92 @@ php: - curl # a dictionary can be used in more complex cases where you want # to pass forward special arguments to the pkg.installed call + # you MUST include the name argument for this to work cli: - php-cli: - fromrepo: my-specialrepo - php-common: + - + name: php-cli fromrepo: my-specialrepo + - + name: php-common + skip_verify: True # php-fpm os-specific settings fpm: - # the main php-fpm config file - conf: /etc/php5/fpm/php-fpm.conf - # the php-fpm php.ini - ini: /etc/php5/fpm/php.ini - # the location where pools are stored - pools: /etc/php5/fpm/pool.d - # the name of the php-fpm service - service: php5-fpm + conf: /location/of/php-fpm/config.conf + ini: /location/of/php-fpm/php.ini + pools: /location/of/php-fpm/pool.d + service: name-of-php5-fpm-service + # the default content of the php5-fpm main config file defaults: global: pid: /var/run/php5-fpm.pid + + # php-cli os-specific settings + cli: + ini: /location/of/php-cli/php.ini + + # php-fpm settings + fpm: + + # settings for the php-fpm service + service: + # if True, enables the php-fpm service, if False disables it + enabled: True + # additional arguments passed forward to + # service.enabled/disabled + opts: + reload: True + + # settings for the relevant php-fpm configuration files + config: + + # options to manage the php.ini file used by php-fpm + ini: + # arguments passed through to file.managed + opts: + recurse: True + # php.ini file contents that will be merged with the + # defaults in php.ng.ini.defaults. See php.ng.ini.defaults for + # syntax guidelines. + settings: + PHP: + engine: 'Off' + + # options to manage the php-fpm conf file + conf: + # arguments passed through to file.managed + opts: + recurse: True + # php-fpm conf file contents that will be merged with + # php.ng.lookup.fpm.defaults. See php.ng.ini.defaults for + # ini-style syntax guidelines. + settings: + global: + pid: /var/run/php-fpm/special-pid.file + + # settings for fpm-pools + pools: + # name of the pool file to be managed, this will be appended + # to the path specified in php.ng.lookup.fpm.pools + 'mypool.conf': + # If true, the pool file will be managed, if False it will be + # absent + enabled: True + # arguments passed forward to file.managed or file.absent + opts: + replace: False + + # pool file contents. See php.ng.ini.defaults for ini-style + # syntax guidelines. + settings: + myapp: + user: www-data + group: www-data + listen: /var/run/php5-fpm-myapp.sock + pm: dynamic + pm.max_children: 5 + pm.start_servers: 2 + pm.min_spare_servers: 1 + pm.max_spare_servers: 3 + 'php_admin_value[memory_limit]': 300M From 7f90be9f9f3a6853425a1ef557ae1b07ebc788ce Mon Sep 17 00:00:00 2001 From: Chad Heuschober Date: Fri, 6 Jun 2014 15:06:49 -0400 Subject: [PATCH 11/11] Finishes first-pass documentation and fixes minor niggle in pools_config. --- php/ng/fpm/pools_config.sls | 4 ++-- pillar.example | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/php/ng/fpm/pools_config.sls b/php/ng/fpm/pools_config.sls index fe255c5..80a9d2f 100644 --- a/php/ng/fpm/pools_config.sls +++ b/php/ng/fpm/pools_config.sls @@ -16,12 +16,12 @@ {{ state }}: {% if config.enabled %} file.managed: - {{ sls_block(config.opts) }} + {{ sls_block(config.get('opts', {})) }} - name: {{ fpath }} - source: salt://php/ng/files/php.ini - template: jinja - context: - config: {{ serialize(config.settings) }} + config: {{ serialize(config.get('settings', {})) }} {% else %} file.absent: - name: {{ fpath }} diff --git a/pillar.example b/pillar.example index 7bd42c8..e45f9ec 100644 --- a/pillar.example +++ b/pillar.example @@ -107,3 +107,34 @@ php: pm.min_spare_servers: 1 pm.max_spare_servers: 3 'php_admin_value[memory_limit]': 300M + + # php-cli settings + cli: + # settings to manage the cli's php.ini + ini: + # opts passed forward directly to file.managed + opts: + replace: False + # contents of the php.ini file that are merged with defaults + # from php.ng.ini.defaults. See php.ng.ini.defaults for ini-style + # syntax guidelines + settings: + PHP: + engine: 'Off' + + # global php.ini settings + ini: + # Default php.ini contents. These follow a strict format. The top- + # level dict keys form ini group headings. Nested key/value + # pairs represent setting=value statements. If a value is a list, + # its contents will be joined by commas in final rendering. + defaults: + PHP: + engine: on + output_buffering: 4096 + disable_functions: + - pcntl_alarm + - pcntl_fork + - pcntl_wait + 'CLI Server': + cli_server_color: 'On'