Saltstack Official Nginx 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.

195 satır
5.7KB

  1. # nginx.pkg
  2. #
  3. # Manages installation of nginx from pkg.
  4. {#- Get the `tplroot` from `tpldir` #}
  5. {%- set tplroot = tpldir.split('/')[0] %}
  6. {%- from tplroot ~ "/map.jinja" import nginx, sls_block with context %}
  7. {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
  8. {%- if nginx.install_from_repo %}
  9. {% set from_official = true %}
  10. {% set from_ppa = false %}
  11. {% set from_phusionpassenger = false %}
  12. {% elif nginx.install_from_ppa %}
  13. {% set from_official = false %}
  14. {% set from_ppa = true %}
  15. {% set from_phusionpassenger = false %}
  16. {% elif nginx.install_from_phusionpassenger %}
  17. {% set from_official = false %}
  18. {% set from_ppa = false %}
  19. {% set from_phusionpassenger = true %}
  20. {% else %}
  21. {% set from_official = false %}
  22. {% set from_ppa = false %}
  23. {% set from_phusionpassenger = false %}
  24. {%- endif %}
  25. {%- set resource_repo_managed = 'file' if grains.os_family == 'Debian' else 'pkgrepo' %}
  26. nginx_install:
  27. pkg.installed:
  28. {{ sls_block(nginx.package.opts) }}
  29. {% if nginx.lookup.package is iterable and nginx.lookup.package is not string %}
  30. - pkgs:
  31. {% for pkg in nginx.lookup.package %}
  32. - {{ pkg }}
  33. {% endfor %}
  34. {% else %}
  35. - name: {{ nginx.lookup.package }}
  36. {% endif %}
  37. {% if grains.os_family == 'Debian' %}
  38. {%- if from_official %}
  39. nginx_official_repo_keyring:
  40. file.managed:
  41. - name: {{ nginx.lookup.package_repo_keyring }}
  42. - source: {{ files_switch(['nginx-archive-keyring.gpg'],
  43. lookup='nginx_official_repo_keyring'
  44. )
  45. }}
  46. - require_in:
  47. - {{ resource_repo_managed }}: nginx_official_repo
  48. {%- endif %}
  49. nginx_official_repo:
  50. file:
  51. {%- if from_official %}
  52. - managed
  53. {%- else %}
  54. - absent
  55. {%- endif %}
  56. - name: /etc/apt/sources.list.d/nginx-official-{{ grains.oscodename }}.list
  57. - contents: >
  58. deb [signed-by={{ nginx.lookup.package_repo_keyring }}]
  59. http://nginx.org/packages/{{ grains.os | lower }}/ {{ grains.oscodename }} nginx
  60. - require_in:
  61. - pkg: nginx_install
  62. - watch_in:
  63. - pkg: nginx_install
  64. {%- if from_phusionpassenger %}
  65. nginx_phusionpassenger_repo_keyring:
  66. file.managed:
  67. - name: /usr/share/keyrings/phusionpassenger-archive-keyring.gpg
  68. - source: {{ files_switch(['phusionpassenger-archive-keyring.gpg'],
  69. lookup='nginx_phusionpassenger_repo_keyring'
  70. )
  71. }}
  72. - require_in:
  73. - {{ resource_repo_managed }}: nginx_phusionpassenger_repo
  74. # Remove the old repo file
  75. nginx_phusionpassenger_repo_remove:
  76. pkgrepo.absent:
  77. - name: deb http://nginx.org/packages/{{ grains.os |lower }}/ {{ grains.oscodename }} nginx
  78. - keyid: 561F9B9CAC40B2F7
  79. - require_in:
  80. - {{ resource_repo_managed }}: nginx_phusionpassenger_repo
  81. file.absent:
  82. - name: /etc/apt/sources.list.d/nginx-phusionpassenger-{{ grains.oscodename }}.list
  83. - require_in:
  84. - {{ resource_repo_managed }}: nginx_phusionpassenger_repo
  85. {%- endif %}
  86. nginx_phusionpassenger_repo:
  87. file:
  88. {%- if from_phusionpassenger %}
  89. - managed
  90. {%- else %}
  91. - absent
  92. {%- endif %}
  93. - name: /etc/apt/sources.list.d/phusionpassenger-official-{{ grains.oscodename }}.list
  94. - contents: >
  95. deb [signed-by={{ nginx.lookup.passenger_package_repo_keyring }}]
  96. https://oss-binaries.phusionpassenger.com/apt/passenger {{ grains.oscodename }} main
  97. - require_in:
  98. - pkg: nginx_install
  99. - watch_in:
  100. - pkg: nginx_install
  101. {% endif %}
  102. {% if grains.os_family == 'Suse' or grains.os == 'SUSE' %}
  103. nginx_zypp_repo:
  104. pkgrepo:
  105. {%- if from_official %}
  106. - managed
  107. {%- else %}
  108. - absent
  109. {%- endif %}
  110. - name: server_http
  111. - humanname: server_http
  112. - baseurl: 'http://download.opensuse.org/repositories/server:/http/openSUSE_13.2/'
  113. - enabled: True
  114. - autorefresh: True
  115. - gpgcheck: {{ nginx.lookup.gpg_check }}
  116. - gpgkey: {{ nginx.lookup.gpg_key }}
  117. - require_in:
  118. - pkg: nginx_install
  119. - watch_in:
  120. - pkg: nginx_install
  121. {% endif %}
  122. {% if grains.os_family == 'RedHat' %}
  123. {% if grains.get('osfinger', '') == 'Amazon Linux-2' %}
  124. nginx_epel_repo:
  125. pkgrepo.managed:
  126. - name: epel
  127. - humanname: Extra Packages for Enterprise Linux 7 - $basearch
  128. - mirrorlist: https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
  129. - enabled: 1
  130. - gpgcheck: 1
  131. - gpgkey: https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7
  132. - failovermethod: priority
  133. - require_in:
  134. - pkg: nginx_install
  135. - watch_in:
  136. - pkg: nginx_install
  137. {% endif %}
  138. nginx_yum_repo:
  139. pkgrepo:
  140. {%- if from_official %}
  141. - managed
  142. {%- else %}
  143. - absent
  144. {%- endif %}
  145. - name: nginx
  146. - humanname: nginx repo
  147. {%- if grains.os == 'CentOS' %}
  148. - baseurl: 'http://nginx.org/packages/centos/$releasever/$basearch/'
  149. {%- else %}
  150. - baseurl: 'http://nginx.org/packages/rhel/{{ nginx.lookup.rh_os_releasever }}/$basearch/'
  151. {%- endif %}
  152. - gpgcheck: {{ nginx.lookup.gpg_check }}
  153. - gpgkey: {{ nginx.lookup.gpg_key }}
  154. - enabled: True
  155. - require_in:
  156. - pkg: nginx_install
  157. - watch_in:
  158. - pkg: nginx_install
  159. nginx_phusionpassenger_yum_repo:
  160. pkgrepo:
  161. {%- if from_phusionpassenger %}
  162. - managed
  163. {%- else %}
  164. - absent
  165. {%- endif %}
  166. - name: passenger
  167. - humanname: nginx phusionpassenger repo
  168. - baseurl: 'https://oss-binaries.phusionpassenger.com/yum/passenger/el/$releasever/$basearch'
  169. - repo_gpgcheck: 1
  170. - gpgcheck: 0
  171. - gpgkey: 'https://oss-binaries.phusionpassenger.com/yum/definitions/RPM-GPG-KEY.asc'
  172. - enabled: True
  173. - sslverify: 1
  174. - sslcacert: /etc/pki/tls/certs/ca-bundle.crt
  175. - require_in:
  176. - pkg: nginx_install
  177. - watch_in:
  178. - pkg: nginx_install
  179. {% endif %}