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.

234 lines
6.3KB

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