Saltstack Official Linux Formula
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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