Saltstack Official PHP Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.1KB

  1. # -*- coding: utf-8 -*-
  2. # vim: ft=jinja
  3. {# Template for installing packages #}
  4. {% from "php/ng/map.jinja" import php with context %}
  5. {% from "php/ng/macro.jinja" import sls_block %}
  6. {% set pkginfo = php.lookup.pkgs.get(state) %}
  7. {% set phpng_version = salt['pillar.get']('php:ng:version', '7.0')|string %}
  8. {% set pkgs = [] %}
  9. {% set specials = [] %}
  10. {% if pkginfo is iterable and pkginfo is not string %}
  11. {% for pkg in pkginfo %}
  12. {% if pkg is mapping %}
  13. {% do specials.append(pkg) %}
  14. {% else %}
  15. {% do pkgs.append(pkg) %}
  16. {% endif %}
  17. {% endfor %}
  18. {% else %}
  19. {% do pkgs.append(pkginfo) %}
  20. {% endif %}
  21. {% if grains['os_family'] == "Debian" and (state == 'cli' or state == 'fpm' or state == 'php') %}
  22. {% set use_external_repo = salt['pillar.get']('php:use_external_repo', False) %}
  23. {% if use_external_repo %}
  24. {% set external_repo_name = salt['pillar.get']('php:external_repo_name', 'ondrej/php') %}
  25. {% set current_php = salt['alternatives.show_current']('php') %}
  26. php_ppa_{{ state }}:
  27. pkgrepo.managed:
  28. - ppa: {{ external_repo_name }}
  29. - env:
  30. - LC_ALL: C.UTF-8
  31. - onlyif:
  32. - test ! -e /etc/apt/sources.list.d/ondrej-ubuntu-php-{{ grains['oscodename'] }}.list {# Trusty and Xenial use different naming schemas #}
  33. - test ! -e /etc/apt/sources.list.d/ondrej-php-{{ grains['oscodename'] }}.list {# Trusty and Xenial use different naming schemas #}
  34. - require_in:
  35. - pkg: php_install_{{ state }}
  36. pkg.latest:
  37. - name: {{ state }}
  38. - pkgs: {{ pkgs|json() }}
  39. - refresh: True
  40. - onchanges:
  41. - pkgrepo: php_ppa_{{ state }}
  42. php_{{ phpng_version }}_link:
  43. alternatives.set:
  44. - name: php
  45. - path: /usr/bin/php{{ phpng_version }}
  46. - require_in:
  47. - pkg: php_install_{{ state }}
  48. - onlyif:
  49. - which php
  50. - test {{ current_php }} != $(which php{{ phpng_version }})
  51. {% endif %}
  52. {% endif %}
  53. php_install_{{ state }}:
  54. pkg.installed:
  55. - name: {{ state }}
  56. - pkgs: {{ pkgs|json() }}
  57. {% for pkg in specials %}
  58. php_install_{{ state }}_{{ pkg.get('name') }}:
  59. pkg.installed:
  60. {{ sls_block(pkg) }}
  61. {% endfor %}