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.

184 line
4.8KB

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