Saltstack Official Linux Formula

197 lines
5.1KB

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