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.

213 lines
5.4KB

  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.iteritems() %}
  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 '{{ repo.key }}' | 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. - human_name: {{ 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. {%- if repo.key_url is defined %}
  98. - key_url: {{ repo.key_url }}
  99. {%- endif %}
  100. - consolidate: {{ repo.get('consolidate', False) }}
  101. - clean_file: {{ repo.get('clean_file', False) }}
  102. - refresh_db: {{ repo.get('refresh_db', True) }}
  103. - require:
  104. - pkg: linux_repo_prereq_pkgs
  105. {%- if repo.get('proxy', {}).get('enabled', False) %}
  106. - file: /etc/apt/apt.conf.d/99proxies-salt-{{ name }}
  107. {%- endif %}
  108. {%- if system.proxy.get('pkg', {}).get('enabled', False) %}
  109. - file: /etc/apt/apt.conf.d/99proxies-salt
  110. {%- endif %}
  111. {%- if system.purge_repos|default(False) %}
  112. - file: purge_sources_list_d_repos
  113. {%- endif %}
  114. {%- endif %}
  115. {%- else %}
  116. linux_repo_{{ name }}_absent:
  117. file.absent:
  118. - name: /etc/apt/sources.list.d/{{ name }}.list
  119. {%- endif %}
  120. {%- endif %}
  121. {%- endif %}
  122. {%- if grains.os_family == "RedHat" %}
  123. {%- if repo.get('proxy', {}).get('enabled', False) %}
  124. # PLACEHOLDER
  125. # TODO, implement per proxy configuration for Yum
  126. {%- endif %}
  127. {%- if not repo.get('default', False) %}
  128. linux_repo_{{ name }}:
  129. pkgrepo.managed:
  130. - name: {{ name }}
  131. - humanname: {{ repo.get('humanname', name) }}
  132. {%- if repo.mirrorlist is defined %}
  133. - mirrorlist: {{ repo.mirrorlist }}
  134. {%- else %}
  135. - baseurl: {{ repo.source }}
  136. {%- endif %}
  137. - gpgcheck: {% if repo.get('gpgcheck', False) %}1{% else %}0{% endif %}
  138. {%- if repo.gpgkey is defined %}
  139. - gpgkey: {{ repo.gpgkey }}
  140. {%- endif %}
  141. - require:
  142. - pkg: linux_repo_prereq_pkgs
  143. {%- endif %}
  144. {%- endif %}
  145. {%- endfor %}
  146. {%- if default_repos|length > 0 and grains.os_family == 'Debian' %}
  147. default_repo_list:
  148. file.managed:
  149. - name: /etc/apt/sources.list
  150. - source: salt://linux/files/sources.list
  151. - template: jinja
  152. - user: root
  153. - group: root
  154. - mode: 0644
  155. {%- if system.purge_repos|default(False) %}
  156. - replace: True
  157. {%- endif %}
  158. - defaults:
  159. default_repos: {{ default_repos }}
  160. - require:
  161. - pkg: linux_repo_prereq_pkgs
  162. refresh_default_repo:
  163. module.wait:
  164. - name: pkg.refresh_db
  165. - watch:
  166. - file: default_repo_list
  167. {%- endif %}
  168. {%- endif %}