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.

211 lines
6.3KB

  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. nginx_install:
  26. pkg.installed:
  27. {{ sls_block(nginx.package.opts) }}
  28. {% if nginx.lookup.package is iterable and nginx.lookup.package is not string %}
  29. - pkgs:
  30. {% for pkg in nginx.lookup.package %}
  31. - {{ pkg }}
  32. {% endfor %}
  33. {% else %}
  34. - name: {{ nginx.lookup.package }}
  35. {% endif %}
  36. {% if salt['grains.get']('os_family') == 'Debian' %}
  37. {%- if from_official %}
  38. nginx_official_repo_keyring:
  39. file.managed:
  40. - name: /usr/share/keyrings/nginx-archive-keyring.gpg
  41. - source: {{ files_switch(['nginx-archive-keyring.gpg'],
  42. lookup='nginx_official_repo_keyring'
  43. )
  44. }}
  45. - require_in:
  46. - pkgrepo: nginx_official_repo
  47. {%- endif %}
  48. nginx_official_repo:
  49. pkgrepo:
  50. {%- if from_official %}
  51. - managed
  52. {%- else %}
  53. - absent
  54. {%- endif %}
  55. - humanname: nginx apt repo
  56. - name: deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/{{ grains['os'].lower() }}/ {{ grains['oscodename'] }} nginx
  57. - file: /etc/apt/sources.list.d/nginx-official-{{ grains['oscodename'] }}.list
  58. - require_in:
  59. - pkg: nginx_install
  60. - watch_in:
  61. - pkg: nginx_install
  62. {%- if grains.os not in ('Debian',) %}
  63. ## applies to Ubuntu and derivatives only #}
  64. nginx_ppa_repo:
  65. pkgrepo:
  66. {%- if from_ppa %}
  67. - managed
  68. {%- else %}
  69. - absent
  70. {%- endif %}
  71. {% if salt['grains.get']('os') == 'Ubuntu' %}
  72. - ppa: nginx/{{ nginx.ppa_version }}
  73. {% else %}
  74. - name: deb http://ppa.launchpad.net/nginx/{{ nginx.ppa_version }}/ubuntu {{ grains['oscodename'] }} main
  75. - keyid: C300EE8C
  76. - keyserver: keyserver.ubuntu.com
  77. {% endif %}
  78. - require_in:
  79. - pkg: nginx_install
  80. - watch_in:
  81. - pkg: nginx_install
  82. {%- endif %}
  83. {%- if from_phusionpassenger %}
  84. nginx_phusionpassenger_repo_keyring:
  85. file.managed:
  86. - name: /usr/share/keyrings/phusionpassenger-archive-keyring.gpg
  87. - source: {{ files_switch(['phusionpassenger-archive-keyring.gpg'],
  88. lookup='nginx_phusionpassenger_repo_keyring'
  89. )
  90. }}
  91. - require_in:
  92. - pkgrepo: nginx_phusionpassenger_repo
  93. # Remove the old repo file
  94. nginx_phusionpassenger_repo_remove:
  95. pkgrepo.absent:
  96. - name: deb http://nginx.org/packages/{{ grains['os'].lower() }}/ {{ grains['oscodename'] }} nginx
  97. - keyid: 561F9B9CAC40B2F7
  98. - require_in:
  99. - pkgrepo: nginx_phusionpassenger_repo
  100. file.absent:
  101. - name: /etc/apt/sources.list.d/nginx-phusionpassenger-{{ grains['oscodename'] }}.list
  102. - require_in:
  103. - pkgrepo: nginx_phusionpassenger_repo
  104. {%- endif %}
  105. nginx_phusionpassenger_repo:
  106. pkgrepo:
  107. {%- if from_phusionpassenger %}
  108. - managed
  109. {%- else %}
  110. - absent
  111. {%- endif %}
  112. - humanname: nginx phusionpassenger repo
  113. - name: deb [signed-by=/usr/share/keyrings/phusionpassenger-archive-keyring.gpg] https://oss-binaries.phusionpassenger.com/apt/passenger {{ grains['oscodename'] }} main
  114. - file: /etc/apt/sources.list.d/phusionpassenger-official-{{ grains['oscodename'] }}.list
  115. - require_in:
  116. - pkg: nginx_install
  117. - watch_in:
  118. - pkg: nginx_install
  119. {% endif %}
  120. {% if salt['grains.get']('os_family') == 'Suse' or salt['grains.get']('os') == 'SUSE' %}
  121. nginx_zypp_repo:
  122. pkgrepo:
  123. {%- if from_official %}
  124. - managed
  125. {%- else %}
  126. - absent
  127. {%- endif %}
  128. - name: server_http
  129. - humanname: server_http
  130. - baseurl: 'http://download.opensuse.org/repositories/server:/http/openSUSE_13.2/'
  131. - enabled: True
  132. - autorefresh: True
  133. - gpgcheck: {{ nginx.lookup.gpg_check }}
  134. - gpgkey: {{ nginx.lookup.gpg_key }}
  135. - require_in:
  136. - pkg: nginx_install
  137. - watch_in:
  138. - pkg: nginx_install
  139. {% endif %}
  140. {% if salt['grains.get']('os_family') == 'RedHat' %}
  141. {% if salt['grains.get']('osfinger', '') in ['Amazon Linux-2'] %}
  142. nginx_epel_repo:
  143. pkgrepo.managed:
  144. - name: epel
  145. - humanname: Extra Packages for Enterprise Linux 7 - $basearch
  146. - mirrorlist: https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
  147. - enabled: 1
  148. - gpgcheck: 1
  149. - gpgkey: https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7
  150. - failovermethod: priority
  151. - require_in:
  152. - pkg: nginx_install
  153. - watch_in:
  154. - pkg: nginx_install
  155. {% endif %}
  156. nginx_yum_repo:
  157. pkgrepo:
  158. {%- if from_official %}
  159. - managed
  160. {%- else %}
  161. - absent
  162. {%- endif %}
  163. - name: nginx
  164. - humanname: nginx repo
  165. {%- if salt['grains.get']('os') == 'CentOS' %}
  166. - baseurl: 'http://nginx.org/packages/centos/$releasever/$basearch/'
  167. {%- else %}
  168. - baseurl: 'http://nginx.org/packages/rhel/{{ nginx.lookup.rh_os_releasever }}/$basearch/'
  169. {%- endif %}
  170. - gpgcheck: {{ nginx.lookup.gpg_check }}
  171. - gpgkey: {{ nginx.lookup.gpg_key }}
  172. - enabled: True
  173. - require_in:
  174. - pkg: nginx_install
  175. - watch_in:
  176. - pkg: nginx_install
  177. nginx_phusionpassenger_yum_repo:
  178. pkgrepo:
  179. {%- if from_phusionpassenger %}
  180. - managed
  181. {%- else %}
  182. - absent
  183. {%- endif %}
  184. - name: passenger
  185. - humanname: nginx phusionpassenger repo
  186. - baseurl: 'https://oss-binaries.phusionpassenger.com/yum/passenger/el/$releasever/$basearch'
  187. - repo_gpgcheck: 1
  188. - gpgcheck: 0
  189. - gpgkey: 'https://oss-binaries.phusionpassenger.com/yum/definitions/RPM-GPG-KEY.asc'
  190. - enabled: True
  191. - sslverify: 1
  192. - sslcacert: /etc/pki/tls/certs/ca-bundle.crt
  193. - require_in:
  194. - pkg: nginx_install
  195. - watch_in:
  196. - pkg: nginx_install
  197. {% endif %}