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.

170 lines
4.5KB

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