Saltstack Official Linux Formula
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

251 lines
6.6KB

  1. {%- from "linux/map.jinja" import system with context %}
  2. {%- if system.enabled %}
  3. linux_repo_prereq_pkgs:
  4. pkg.installed:
  5. - pkgs: {{ system.pkgs }}
  6. # global proxy setup
  7. {%- if system.proxy.get('pkg', {}).get('enabled', False) %}
  8. {%- if grains.os_family == 'Debian' %}
  9. /etc/apt/apt.conf.d/99proxies-salt:
  10. file.managed:
  11. - template: jinja
  12. - source: salt://linux/files/apt.conf.d_proxies
  13. - defaults:
  14. external_host: False
  15. https: {{ system.proxy.get('pkg', {}).get('https', None) | default(system.proxy.get('https', None), true) }}
  16. http: {{ system.proxy.get('pkg', {}).get('http', None) | default(system.proxy.get('http', None), true) }}
  17. ftp: {{ system.proxy.get('pkg', {}).get('ftp', None) | default(system.proxy.get('ftp', None), true) }}
  18. {%- else %}
  19. /etc/apt/apt.conf.d/99proxies-salt:
  20. file.absent
  21. {%- endif %}
  22. {%- endif %}
  23. {% set default_repos = {} %}
  24. {%- if system.purge_repos|default(False) %}
  25. purge_sources_list_d_repos:
  26. file.directory:
  27. - name: /etc/apt/sources.list.d/
  28. - clean: True
  29. {%- endif %}
  30. {%- for name, repo in system.repo.items() %}
  31. {%- set name=repo.get('name', name) %}
  32. {%- if grains.os_family == 'Debian' %}
  33. # per repository proxy setup
  34. {%- if repo.get('proxy', {}).get('enabled', False) %}
  35. {%- set external_host = repo.proxy.get('host', None) or repo.source.split('/')[2] %}
  36. /etc/apt/apt.conf.d/99proxies-salt-{{ name }}:
  37. file.managed:
  38. - template: jinja
  39. - source: salt://linux/files/apt.conf.d_proxies
  40. - defaults:
  41. external_host: {{ external_host }}
  42. https: {{ repo.proxy.get('https', None) or system.proxy.get('pkg', {}).get('https', None) | default(system.proxy.get('https', None), True) }}
  43. http: {{ repo.proxy.get('http', None) or system.proxy.get('pkg', {}).get('http', None) | default(system.proxy.get('http', None), True) }}
  44. ftp: {{ repo.proxy.get('ftp', None) or system.proxy.get('pkg', {}).get('ftp', None) | default(system.proxy.get('ftp', None), True) }}
  45. {%- else %}
  46. /etc/apt/apt.conf.d/99proxies-salt-{{ name }}:
  47. file.absent
  48. {%- endif %}
  49. {%- if repo.pin is defined %}
  50. linux_repo_{{ name }}_pin:
  51. file.managed:
  52. - name: /etc/apt/preferences.d/{{ name }}
  53. - source: salt://linux/files/preferences_repo
  54. - template: jinja
  55. - defaults:
  56. repo_name: {{ name }}
  57. {%- else %}
  58. linux_repo_{{ name }}_pin:
  59. file.absent:
  60. - name: /etc/apt/preferences.d/{{ name }}
  61. {%- endif %}
  62. {%- if repo.get('default', False) %}
  63. {%- do default_repos.update({name: repo}) %}
  64. {%- if repo.get('key') %}
  65. linux_repo_{{ name }}_key:
  66. cmd.wait:
  67. - name: echo -e '{{ repo.key|replace('\n', '\\n') }}' | apt-key add -
  68. - watch:
  69. - file: default_repo_list
  70. {%- elif repo.key_url|default(False) %}
  71. linux_repo_{{ name }}_key:
  72. cmd.wait:
  73. - name: "curl -s {{ repo.key_url }} | apt-key add -"
  74. - watch:
  75. - file: default_repo_list
  76. {%- endif %}
  77. {%- else %}
  78. {%- if repo.get('enabled', True) %}
  79. linux_repo_{{ name }}:
  80. pkgrepo.managed:
  81. {%- if repo.ppa is defined %}
  82. - ppa: {{ repo.ppa }}
  83. {%- else %}
  84. - humanname: {{ name }}
  85. - name: {{ repo.source }}
  86. {%- if repo.architectures is defined %}
  87. - architectures: {{ repo.architectures }}
  88. {%- endif %}
  89. - file: /etc/apt/sources.list.d/{{ name }}.list
  90. - clean_file: {{ repo.clean|default(True) }}
  91. {%- if repo.key_id is defined %}
  92. - keyid: {{ repo.key_id }}
  93. {%- endif %}
  94. {%- if repo.key_server is defined %}
  95. - keyserver: {{ repo.key_server }}
  96. {%- endif %}
  97. - consolidate: {{ repo.get('consolidate', False) }}
  98. - clean_file: {{ repo.get('clean_file', False) }}
  99. - refresh_db: {{ repo.get('refresh_db', True) }}
  100. - require:
  101. - pkg: linux_repo_prereq_pkgs
  102. {%- if repo.get('proxy', {}).get('enabled', False) %}
  103. - file: /etc/apt/apt.conf.d/99proxies-salt-{{ name }}
  104. {%- endif %}
  105. {%- if system.proxy.get('pkg', {}).get('enabled', False) %}
  106. - file: /etc/apt/apt.conf.d/99proxies-salt
  107. {%- endif %}
  108. {%- if system.purge_repos|default(False) %}
  109. - file: purge_sources_list_d_repos
  110. {%- endif %}
  111. {%- endif %}
  112. {%- if repo.get('key') %}
  113. linux_repo_{{ name }}_key:
  114. cmd.run:
  115. - name: echo -e '{{ repo.key|replace('\n', '\\n') }}' | apt-key add -
  116. - unless: apt-key finger --with-colons | grep -qF $(echo -e '{{ repo.key|replace('\n', '\\n') }}' | gpg --with-fingerprint --with-colons | grep -E '^fpr')
  117. - require_in:
  118. - pkgrepo: linux_repo_{{ name }}
  119. {%- elif repo.key_url|default(False) %}
  120. linux_repo_{{ name }}_key:
  121. cmd.run:
  122. - name: "curl -s {{ repo.key_url }} | apt-key add -"
  123. - unless: "apt-key finger --with-colons | grep -qF $(curl -s {{ repo.key_url }} | gpg --with-fingerprint --with-colons | grep -E '^fpr')"
  124. - require_in:
  125. - pkgrepo: linux_repo_{{ name }}
  126. {%- endif %}
  127. {%- else %}
  128. linux_repo_{{ name }}_absent:
  129. pkgrepo.absent:
  130. {%- if repo.ppa is defined %}
  131. - ppa: {{ repo.ppa }}
  132. {%- if repo.key_id is defined %}
  133. - keyid_ppa: {{ repo.keyid_ppa }}
  134. {%- endif %}
  135. {%- else %}
  136. - file: /etc/apt/sources.list.d/{{ name }}.list
  137. {%- if repo.key_id is defined %}
  138. - keyid: {{ repo.key_id }}
  139. {%- endif %}
  140. {%- endif %}
  141. file.absent:
  142. - name: /etc/apt/sources.list.d/{{ name }}.list
  143. {%- endif %}
  144. {%- endif %}
  145. {#- os_family Debian #}
  146. {%- endif %}
  147. {%- if grains.os_family == "RedHat" %}
  148. {%- if repo.get('enabled', True) %}
  149. {%- if repo.get('proxy', {}).get('enabled', False) %}
  150. # PLACEHOLDER
  151. # TODO, implement per proxy configuration for Yum
  152. {%- endif %}
  153. {%- if not repo.get('default', False) %}
  154. linux_repo_{{ name }}:
  155. pkgrepo.managed:
  156. - name: {{ name }}
  157. - humanname: {{ repo.get('humanname', name) }}
  158. {%- if repo.mirrorlist is defined %}
  159. - mirrorlist: {{ repo.mirrorlist }}
  160. {%- else %}
  161. - baseurl: {{ repo.source }}
  162. {%- endif %}
  163. - gpgcheck: {% if repo.get('gpgcheck', False) %}1{% else %}0{% endif %}
  164. {%- if repo.gpgkey is defined %}
  165. - gpgkey: {{ repo.gpgkey }}
  166. {%- endif %}
  167. - require:
  168. - pkg: linux_repo_prereq_pkgs
  169. {%- endif %}
  170. {#- repo.enabled is false #}
  171. {%- else %}
  172. pkgrepo.absent:
  173. - name: {{ repo.source }}
  174. {%- endif %}
  175. {#- os_family Redhat #}
  176. {%- endif %}
  177. {#- repo.items() loop #}
  178. {%- endfor %}
  179. {%- if default_repos|length > 0 and grains.os_family == 'Debian' %}
  180. default_repo_list:
  181. file.managed:
  182. - name: /etc/apt/sources.list
  183. - source: salt://linux/files/sources.list
  184. - template: jinja
  185. - user: root
  186. - group: root
  187. - mode: 0644
  188. {%- if system.purge_repos|default(False) %}
  189. - replace: True
  190. {%- endif %}
  191. - defaults:
  192. default_repos: {{ default_repos }}
  193. - require:
  194. - pkg: linux_repo_prereq_pkgs
  195. refresh_default_repo:
  196. module.wait:
  197. - name: pkg.refresh_db
  198. - watch:
  199. - file: default_repo_list
  200. {%- endif %}
  201. {%- endif %}