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.

119 lines
4.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 pkgs = [] %}
  8. {% set specials = [] %}
  9. {% if pkginfo is iterable and pkginfo is not string %}
  10. {% for pkg in pkginfo %}
  11. {% if pkg is mapping %}
  12. {% do specials.append(pkg) %}
  13. {% else %}
  14. {% do pkgs.append(pkg) %}
  15. {% if salt['pillar.get']('php:ng:version') is iterable %}
  16. {% set first_version = salt['pillar.get']('php:ng:version')[0]|string %}
  17. {% for other_version in salt['pillar.get']('php:ng:version') %}
  18. {% set other_version_str = other_version|string %}
  19. {% do pkgs.append(pkg.replace(first_version, other_version_str)) %}
  20. {% endfor %}
  21. {% endif %}
  22. {% endif %}
  23. {% endfor %}
  24. {% else %}
  25. {% do pkgs.append(pkginfo) %}
  26. {% if salt['pillar.get']('php:ng:version') is iterable %}
  27. {% set first_version = salt['pillar.get']('php:ng:version')[0]|string %}
  28. {% for other_version in salt['pillar.get']('php:ng:version') %}
  29. {% set other_version_str = other_version|string %}
  30. {% do pkgs.append(pkginfo.replace(first_version, other_version_str)) %}
  31. {% endfor %}
  32. {% endif %}
  33. {% endif %}
  34. {% if grains['os_family'] == "Debian" and (state == 'cli' or state == 'fpm' or state == 'php') %}
  35. {% set use_external_repo = salt['pillar.get']('php:use_external_repo', False) %}
  36. {% if use_external_repo %}
  37. {% if grains['os'] == 'Ubuntu' %}
  38. {% set external_repo_name = salt['pillar.get']('php:external_repo_name', 'ondrej/php') %}
  39. php_ppa_{{ state }}:
  40. pkgrepo.managed:
  41. - ppa: {{ external_repo_name }}
  42. - __env__:
  43. - LC_ALL: C.UTF-8
  44. - onlyif:
  45. - test ! -e /etc/apt/sources.list.d/ondrej-ubuntu-php-{{ grains['oscodename'] }}.list {# Trusty and Xenial use different naming schemas #}
  46. - test ! -e /etc/apt/sources.list.d/ondrej-php-{{ grains['oscodename'] }}.list {# Trusty and Xenial use different naming schemas #}
  47. - require_in:
  48. - pkg: php_install_{{ state }}
  49. pkg.latest:
  50. - name: {{ state }}
  51. - pkgs: {{ pkgs|json() }}
  52. - refresh: True
  53. - onchanges:
  54. - pkgrepo: php_ppa_{{ state }}
  55. {% else %}
  56. {% set external_repo_name = salt['pillar.get']('php:external_repo_name', 'packages.sury.org/php' ) %}
  57. php_repo_{{ state }}:
  58. pkg.installed:
  59. - name: apt-transport-https
  60. php_ppa_{{ state }}:
  61. pkgrepo.managed:
  62. - humanname: {{ external_repo_name }}
  63. - name: deb https://packages.sury.org/php/ {{ grains['oscodename'] }} main
  64. - file: /etc/apt/sources.list.d/ondrej-php.list
  65. - key_url: https://packages.sury.org/php/apt.gpg
  66. - __env__:
  67. - LC_ALL: C.UTF-8
  68. - onlyif:
  69. - test ! -e /etc/apt/sources.list.d/ondrej-php.list
  70. - require_in:
  71. - pkg: php_install_{{ state }}
  72. pkg.latest:
  73. - name: {{ state }}
  74. - pkgs: {{ pkgs|json() }}
  75. - refresh: True
  76. - onchanges:
  77. - pkgrepo: php_ppa_{{ state }}
  78. {% endif %}
  79. {% endif %}
  80. {% elif grains['os_family'] == "RedHat" and (state == 'cli' or state == 'fpm' or state == 'php') %}
  81. {% set use_scl_repo = salt['pillar.get']('php:use_scl_repo', False) %}
  82. {% set scl_php_version = salt['pillar.get']('php:scl_php_version', 71) %}
  83. {% set enable_php_repo = salt['pillar.get']('php:ng:lookup:enable_php_repo', False) %}
  84. {% if use_scl_repo and grains['os'] == 'CentOS' %}
  85. php_centos_scl_enable_{{ state }}:
  86. pkg.installed:
  87. - name: centos-release-scl
  88. {% elif use_scl_repo and grains['os'] == 'RedHat' %}
  89. php_redhat_scl_enable_{{ state }}:
  90. cmd.run:
  91. - name: yum-config-manager --enable rhel-server-rhscl-{{ grains['osmajorrelease'] }}-rpms
  92. {% endif %}
  93. {% endif %}
  94. php_install_{{ state }}:
  95. pkg.installed:
  96. - name: {{ state }}
  97. - pkgs: {{ pkgs|json() }}
  98. {% if enable_php_repo is defined and enable_php_repo %}
  99. - enablerepo: {{ enable_php_repo }}
  100. {% endif %}
  101. {% for pkg in specials %}
  102. php_install_{{ state }}_{{ pkg.get('name') | replace("/", "-") }}:
  103. pkg.installed:
  104. {{ sls_block(pkg) }}
  105. {% endfor %}