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.

122 lines
4.2KB

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