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.

153 lines
4.0KB

  1. # nginx.ng.install
  2. #
  3. # Manages installation of nginx.
  4. {% from 'nginx/ng/map.jinja' import nginx, sls_block with context %}
  5. {% if nginx.install_from_source %}
  6. nginx_build_dep:
  7. {% if salt['grains.get']('os_family') == 'Debian' %}
  8. cmd.run:
  9. - name: apt-get -y build-dep nginx
  10. {% elif salt['grains.get']('os_family') == 'RedHat' %}
  11. cmd.run:
  12. - name: yum-builddep -y nginx
  13. {% else %}
  14. ## install build deps for other distros
  15. {% endif %}
  16. nginx_download:
  17. archive.extracted:
  18. - name: /tmp/
  19. - source: http://nginx.org/download/nginx-{{ nginx.source_version }}.tar.gz
  20. - source_hash: sha256={{ nginx.source_hash }}
  21. - archive_format: tar
  22. - if_missing: /usr/sbin/nginx-{{ nginx.source_version }}
  23. - require:
  24. - cmd: nginx_build_dep
  25. - onchanges:
  26. - cmd: nginx_build_dep
  27. nginx_configure:
  28. cmd.run:
  29. - name: ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf {{ nginx.source.opts | join(' ') }}
  30. - cwd: /tmp/nginx-{{ nginx.source_version }}
  31. - require:
  32. - archive: nginx_download
  33. - onchanges:
  34. - archive: nginx_download
  35. nginx_compile:
  36. cmd.run:
  37. - name: make
  38. - cwd: /tmp/nginx-{{ nginx.source_version }}
  39. - require:
  40. - cmd: nginx_configure
  41. {% endif %}
  42. nginx_install:
  43. {% if nginx.install_from_source %}
  44. cmd.run:
  45. - name: make install
  46. - cwd: /tmp/nginx-{{ nginx.source_version }}
  47. - require:
  48. - cmd: nginx_compile
  49. - onchanges:
  50. - cmd: nginx_compile
  51. {% else %}
  52. pkg.installed:
  53. {{ sls_block(nginx.package.opts) }}
  54. - name: {{ nginx.lookup.package }}
  55. {% endif %}
  56. {% if nginx.install_from_source %}
  57. nginx_link:
  58. file.copy:
  59. - name: /usr/sbin/nginx-{{ nginx.source_version }}
  60. - source: /usr/sbin/nginx
  61. - require:
  62. - cmd: nginx_install
  63. - onchanges:
  64. - cmd: nginx_install
  65. {% endif %}
  66. {% if salt['grains.get']('os_family') == 'Debian' %}
  67. {%- if nginx.install_from_repo %}
  68. nginx-official-repo:
  69. pkgrepo:
  70. - managed
  71. - humanname: nginx apt repo
  72. - name: deb http://nginx.org/packages/{{ grains['os'].lower() }}/ {{ grains['oscodename'] }} nginx
  73. - file: /etc/apt/sources.list.d/nginx-official-{{ grains['oscodename'] }}.list
  74. - keyid: ABF5BD827BD9BF62
  75. - keyserver: keyserver.ubuntu.com
  76. - require_in:
  77. - pkg: nginx
  78. - watch_in:
  79. - pkg: nginx
  80. {%- else %}
  81. nginx_ppa_repo:
  82. pkgrepo:
  83. {%- if nginx.install_from_ppa %}
  84. - managed
  85. {%- else %}
  86. - absent
  87. {%- endif %}
  88. {% if salt['grains.get']('os') == 'Ubuntu' %}
  89. - ppa: nginx/{{ nginx.ppa_version }}
  90. {% else %}
  91. - name: deb http://ppa.launchpad.net/nginx/{{ nginx.ppa_version }}/ubuntu trusty main
  92. - keyid: C300EE8C
  93. - keyserver: keyserver.ubuntu.com
  94. {% endif %}
  95. - require_in:
  96. - pkg: nginx_install
  97. - watch_in:
  98. - pkg: nginx_install
  99. {%- endif %}
  100. {% endif %}
  101. {% if salt['grains.get']('os_family') == 'Suse' %}
  102. nginx_zypp_repo:
  103. pkgrepo:
  104. {%- if nginx.install_from_repo %}
  105. - managed
  106. {%- else %}
  107. - absent
  108. {%- endif %}
  109. - name: server_http
  110. - humanname: server_http
  111. - baseurl: 'http://download.opensuse.org/repositories/server:/http/openSUSE_13.2/'
  112. - enabled: True
  113. - autorefresh: True
  114. - gpgcheck: {{ nginx.lookup.gpg_check }}
  115. - gpgkey: {{ nginx.lookup.gpg_key }}
  116. - require_in:
  117. - pkg: nginx_install
  118. - watch_in:
  119. - pkg: nginx_install
  120. {% endif %}
  121. {% if salt['grains.get']('os_family') == 'RedHat' %}
  122. nginx_yum_repo:
  123. {%- if nginx.install_from_repo %}
  124. pkgrepo.managed:
  125. {%- else %}
  126. pkgrepo.absent:
  127. {%- endif %}
  128. - name: nginx
  129. - humanname: nginx repo
  130. {%- if salt['grains.get']('os') == 'CentOS' %}
  131. - baseurl: 'http://nginx.org/packages/centos/$releasever/$basearch/'
  132. {%- else %}
  133. - baseurl: 'http://nginx.org/packages/rhel/{{ nginx.lookup.rh_os_releasever }}/$basearch/'
  134. {%- endif %}
  135. - gpgcheck: {{ nginx.lookup.gpg_check }}
  136. - gpgkey: {{ nginx.lookup.gpg_key }}
  137. - enabled: True
  138. - require_in:
  139. - pkg: nginx_install
  140. - watch_in:
  141. - pkg: nginx_install
  142. {% endif %}