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.

193 lines
5.0KB

  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. {%- if grains.os_family == 'Debian' %}
  32. # per repository proxy setup
  33. {%- if repo.get('proxy', {}).get('enabled', False) %}
  34. {%- set external_host = repo.proxy.get('host', None) or repo.source.split('/')[2] %}
  35. /etc/apt/apt.conf.d/99proxies-salt-{{ name }}:
  36. file.managed:
  37. - template: jinja
  38. - source: salt://linux/files/apt.conf.d_proxies
  39. - defaults:
  40. external_host: {{ external_host }}
  41. https: {{ repo.proxy.get('https', None) or system.proxy.get('pkg', {}).get('https', None) | default(system.proxy.get('https', None), True) }}
  42. http: {{ repo.proxy.get('http', None) or system.proxy.get('pkg', {}).get('http', None) | default(system.proxy.get('http', None), True) }}
  43. ftp: {{ repo.proxy.get('ftp', None) or system.proxy.get('pkg', {}).get('ftp', None) | default(system.proxy.get('ftp', None), True) }}
  44. {%- else %}
  45. /etc/apt/apt.conf.d/99proxies-salt-{{ name }}:
  46. file.absent
  47. {%- endif %}
  48. {%- if repo.pin is defined %}
  49. linux_repo_{{ name }}_pin:
  50. file.managed:
  51. - name: /etc/apt/preferences.d/{{ name }}
  52. - source: salt://linux/files/preferences_repo
  53. - template: jinja
  54. - defaults:
  55. repo_name: {{ name }}
  56. {%- else %}
  57. linux_repo_{{ name }}_pin:
  58. file.absent:
  59. - name: /etc/apt/preferences.d/{{ name }}
  60. {%- endif %}
  61. {%- if repo.get('default', False) %}
  62. {%- do default_repos.update({name: repo}) %}
  63. {%- if repo.get('key') %}
  64. linux_repo_{{ name }}_key:
  65. cmd.wait:
  66. - name: "echo '{{ repo.key }}' | apt-key add -"
  67. - watch:
  68. - file: default_repo_list
  69. {%- elif repo.key_url|default(False) %}
  70. linux_repo_{{ name }}_key:
  71. cmd.wait:
  72. - name: "curl -s {{ repo.key_url }} | apt-key add -"
  73. - watch:
  74. - file: default_repo_list
  75. {%- endif %}
  76. {%- else %}
  77. linux_repo_{{ name }}:
  78. pkgrepo.managed:
  79. - human_name: {{ name }}
  80. - name: {{ repo.source }}
  81. {%- if repo.architectures is defined %}
  82. - architectures: {{ repo.architectures }}
  83. {%- endif %}
  84. - file: /etc/apt/sources.list.d/{{ name }}.list
  85. - clean_file: {{ repo.clean|default(True) }}
  86. {%- if repo.key_id is defined %}
  87. - keyid: {{ repo.key_id }}
  88. {%- endif %}
  89. {%- if repo.key_server is defined %}
  90. - keyserver: {{ repo.key_server }}
  91. {%- endif %}
  92. {%- if repo.key_url is defined %}
  93. - key_url: {{ repo.key_url }}
  94. {%- endif %}
  95. - consolidate: {{ repo.get('consolidate', False) }}
  96. - clean_file: {{ repo.get('clean_file', False) }}
  97. - refresh_db: {{ repo.get('refresh_db', True) }}
  98. - require:
  99. - pkg: linux_repo_prereq_pkgs
  100. {%- if repo.get('proxy', {}).get('enabled', False) %}
  101. - file: /etc/apt/apt.conf.d/99proxies-salt-{{ name }}
  102. {%- endif %}
  103. {%- if system.proxy.get('pkg', {}).get('enabled', False) %}
  104. - file: /etc/apt/apt.conf.d/99proxies-salt
  105. {%- endif %}
  106. {%- if system.purge_repos|default(False) %}
  107. - file: purge_sources_list_d_repos
  108. {%- endif %}
  109. {%- endif %}
  110. {%- endif %}
  111. {%- if grains.os_family == "RedHat" %}
  112. {%- if repo.get('proxy', {}).get('enabled', False) %}
  113. # PLACEHOLDER
  114. # TODO, implement per proxy configuration for Yum
  115. {%- endif %}
  116. {%- if not repo.get('default', False) %}
  117. linux_repo_{{ name }}:
  118. pkgrepo.managed:
  119. - name: {{ name }}
  120. - humanname: {{ repo.get('humanname', name) }}
  121. {%- if repo.mirrorlist is defined %}
  122. - mirrorlist: {{ repo.mirrorlist }}
  123. {%- else %}
  124. - baseurl: {{ repo.source }}
  125. {%- endif %}
  126. - gpgcheck: {% if repo.get('gpgcheck', False) %}1{% else %}0{% endif %}
  127. {%- if repo.gpgkey is defined %}
  128. - gpgkey: {{ repo.gpgkey }}
  129. {%- endif %}
  130. - require:
  131. - pkg: linux_repo_prereq_pkgs
  132. {%- endif %}
  133. {%- endif %}
  134. {%- endfor %}
  135. {%- if default_repos|length > 0 and grains.os_family == 'Debian' %}
  136. default_repo_list:
  137. file.managed:
  138. - name: /etc/apt/sources.list
  139. - source: salt://linux/files/sources.list
  140. - template: jinja
  141. - user: root
  142. - group: root
  143. - mode: 0644
  144. {%- if system.purge_repos %}
  145. - replace: True
  146. {%- endif %}
  147. - defaults:
  148. default_repos: {{ default_repos }}
  149. - require:
  150. - pkg: linux_repo_prereq_pkgs
  151. {%- endif %}
  152. {%- endif %}