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

242 lines
6.5KB

  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('key') %} {# 2 #}
  63. linux_repo_{{ name }}_key:
  64. cmd.run:
  65. - name: |
  66. echo "{{ repo.key | indent(12) }}" | apt-key add -
  67. - unless: |
  68. apt-key finger --with-colons | grep -qF $(echo "{{ repo.key| indent(12) }}" | gpg --with-fingerprint --with-colons | grep -E '^fpr')
  69. - require_in:
  70. {%- if repo.get('default', False) %}
  71. - file: default_repo_list
  72. {% else %}
  73. - pkgrepo: linux_repo_{{ name }}
  74. {% endif %}
  75. {%- elif repo.key_url|default(False) %}
  76. linux_repo_{{ name }}_key:
  77. cmd.run:
  78. - name: "curl -sL {{ repo.key_url }} | apt-key add -"
  79. - unless: "apt-key finger --with-colons | grep -qF $(curl -sL {{ repo.key_url }} | gpg --with-fingerprint --with-colons | grep -E '^fpr')"
  80. - require_in:
  81. {%- if repo.get('default', False) %}
  82. - file: default_repo_list
  83. {% else %}
  84. - pkgrepo: linux_repo_{{ name }}
  85. {% endif %}
  86. {%- endif %} {# 2 #}
  87. {%- if repo.get('default', False) %} {# 1 #}
  88. {%- do default_repos.update({name: repo}) %} {# for 'default' repos #}
  89. {%- else %} {# for all others repos #}
  90. {%- if repo.get('enabled', True) %}
  91. linux_repo_{{ name }}:
  92. pkgrepo.managed:
  93. {%- if repo.ppa is defined %}
  94. - ppa: {{ repo.ppa }}
  95. {%- else %}
  96. - humanname: {{ name }}
  97. - name: {{ repo.source }}
  98. {%- if repo.architectures is defined %}
  99. - architectures: {{ repo.architectures }}
  100. {%- endif %}
  101. - file: /etc/apt/sources.list.d/{{ name }}.list
  102. - clean_file: {{ repo.clean|default(True) }}
  103. {%- if repo.key_id is defined %}
  104. - keyid: {{ repo.key_id }}
  105. {%- endif %}
  106. {%- if repo.key_server is defined %}
  107. - keyserver: {{ repo.key_server }}
  108. {%- endif %}
  109. - consolidate: {{ repo.get('consolidate', False) }}
  110. - clean_file: {{ repo.get('clean_file', False) }}
  111. - refresh_db: {{ repo.get('refresh_db', True) }}
  112. - require:
  113. - pkg: linux_repo_prereq_pkgs
  114. {%- if repo.get('proxy', {}).get('enabled', False) %}
  115. - file: /etc/apt/apt.conf.d/99proxies-salt-{{ name }}
  116. {%- endif %}
  117. {%- if system.proxy.get('pkg', {}).get('enabled', False) %}
  118. - file: /etc/apt/apt.conf.d/99proxies-salt
  119. {%- endif %}
  120. {%- if system.purge_repos|default(False) %}
  121. - file: purge_sources_list_d_repos
  122. {%- endif %}
  123. {%- endif %}
  124. {%- else %}
  125. linux_repo_{{ name }}_absent:
  126. pkgrepo.absent:
  127. {%- if repo.ppa is defined %}
  128. - ppa: {{ repo.ppa }}
  129. {%- if repo.key_id is defined %}
  130. - keyid_ppa: {{ repo.keyid_ppa }}
  131. {%- endif %}
  132. {%- else %}
  133. - file: /etc/apt/sources.list.d/{{ name }}.list
  134. {%- if repo.key_id is defined %}
  135. - keyid: {{ repo.key_id }}
  136. {%- endif %}
  137. {%- endif %}
  138. file.absent:
  139. - name: /etc/apt/sources.list.d/{{ name }}.list
  140. {%- endif %}
  141. {%- endif %} {# 1 #}
  142. {#- os_family Debian #}
  143. {%- endif %}
  144. {%- if grains.os_family == "RedHat" %}
  145. {%- if repo.get('enabled', True) %}
  146. {%- if repo.get('proxy', {}).get('enabled', False) %}
  147. # PLACEHOLDER
  148. # TODO, implement per proxy configuration for Yum
  149. {%- endif %}
  150. {%- if not repo.get('default', False) %}
  151. linux_repo_{{ name }}:
  152. pkgrepo.managed:
  153. - name: {{ name }}
  154. - humanname: {{ repo.get('humanname', name) }}
  155. {%- if repo.mirrorlist is defined %}
  156. - mirrorlist: {{ repo.mirrorlist }}
  157. {%- else %}
  158. - baseurl: {{ repo.source }}
  159. {%- endif %}
  160. - gpgcheck: {% if repo.get('gpgcheck', False) %}1{% else %}0{% endif %}
  161. {%- if repo.gpgkey is defined %}
  162. - gpgkey: {{ repo.gpgkey }}
  163. {%- endif %}
  164. - require:
  165. - pkg: linux_repo_prereq_pkgs
  166. {%- endif %}
  167. {#- repo.enabled is false #}
  168. {%- else %}
  169. pkgrepo.absent:
  170. - name: {{ repo.source }}
  171. {%- endif %}
  172. {#- os_family Redhat #}
  173. {%- endif %}
  174. {#- repo.items() loop #}
  175. {%- endfor %}
  176. {%- if default_repos|length > 0 and grains.os_family == 'Debian' %}
  177. default_repo_list:
  178. file.managed:
  179. - name: /etc/apt/sources.list
  180. - source: salt://linux/files/sources.list
  181. - template: jinja
  182. - user: root
  183. - group: root
  184. - mode: 0644
  185. {%- if system.purge_repos|default(False) %}
  186. - replace: True
  187. {%- endif %}
  188. - defaults:
  189. default_repos: {{ default_repos }}
  190. - require:
  191. - pkg: linux_repo_prereq_pkgs
  192. refresh_default_repo:
  193. module.wait:
  194. - name: pkg.refresh_db
  195. - watch:
  196. - file: default_repo_list
  197. {%- endif %}
  198. {%- endif %}