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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. {%- from "linux/map.jinja" import system with context %}
  2. {%- if system.enabled %}
  3. {% if system.pkgs %}
  4. linux_repo_prereq_pkgs:
  5. pkg.installed:
  6. - pkgs: {{ system.pkgs | json }}
  7. {%- endif %}
  8. # global proxy setup
  9. {%- if grains.os_family == 'Debian' %}
  10. {%- if system.proxy.get('pkg', {}).get('enabled', False) %}
  11. /etc/apt/apt.conf.d/99proxies-salt:
  12. file.managed:
  13. - template: jinja
  14. - source: salt://linux/files/apt.conf.d_proxies
  15. - defaults:
  16. external_host: False
  17. https: {{ system.proxy.get('pkg', {}).get('https', None) | default(system.proxy.get('https', None), true) }}
  18. http: {{ system.proxy.get('pkg', {}).get('http', None) | default(system.proxy.get('http', None), true) }}
  19. ftp: {{ system.proxy.get('pkg', {}).get('ftp', None) | default(system.proxy.get('ftp', None), true) }}
  20. {%- else %}
  21. /etc/apt/apt.conf.d/99proxies-salt:
  22. file.absent
  23. {%- endif %}
  24. {%- else %}
  25. # Implement grobal proxy configiration for non-debian OS.
  26. {%- endif %}
  27. {% set default_repos = {} %}
  28. {%- if system.purge_repos|default(False) %}
  29. purge_sources_list_d_repos:
  30. file.directory:
  31. - name: /etc/apt/sources.list.d/
  32. - clean: True
  33. {%- endif %}
  34. {%- for name, repo in system.repo.items() %}
  35. {%- set name=repo.get('name', name) %}
  36. {%- if grains.os_family == 'Debian' %}
  37. # per repository proxy setup
  38. {%- if repo.get('proxy', {}).get('enabled', False) %}
  39. {%- set external_host = repo.proxy.get('host', None) or repo.source.split('/')[2] %}
  40. /etc/apt/apt.conf.d/99proxies-salt-{{ name }}:
  41. file.managed:
  42. - template: jinja
  43. - source: salt://linux/files/apt.conf.d_proxies
  44. - defaults:
  45. external_host: {{ external_host }}
  46. https: {{ repo.proxy.get('https', None) or system.proxy.get('pkg', {}).get('https', None) | default(system.proxy.get('https', None), True) }}
  47. http: {{ repo.proxy.get('http', None) or system.proxy.get('pkg', {}).get('http', None) | default(system.proxy.get('http', None), True) }}
  48. ftp: {{ repo.proxy.get('ftp', None) or system.proxy.get('pkg', {}).get('ftp', None) | default(system.proxy.get('ftp', None), True) }}
  49. {%- else %}
  50. /etc/apt/apt.conf.d/99proxies-salt-{{ name }}:
  51. file.absent
  52. {%- endif %}
  53. {%- if repo.pin is defined or repo.pinning is defined %}
  54. linux_repo_{{ name }}_pin:
  55. file.managed:
  56. - name: /etc/apt/preferences.d/{{ name }}
  57. - source: salt://linux/files/preferences_repo
  58. - template: jinja
  59. - defaults:
  60. repo_name: {{ name }}
  61. {%- else %}
  62. linux_repo_{{ name }}_pin:
  63. file.absent:
  64. - name: /etc/apt/preferences.d/{{ name }}
  65. {%- endif %}
  66. {%- if repo.get('key') %}
  67. linux_repo_{{ name }}_key:
  68. {% set repo_key = salt['hashutil.base64_b64encode'](repo.key) %}
  69. cmd.run:
  70. - name: "echo '{{ repo_key }}' | base64 -d | apt-key add -"
  71. - require_in:
  72. {%- if repo.get('default', False) %}
  73. - file: default_repo_list
  74. {% else %}
  75. - pkgrepo: linux_repo_{{ name }}
  76. {% endif %}
  77. {# key_url fetch by curl when salt <2017.7, higher version of salt has
  78. fixed bug for using a proxy_host/port specified at minion.conf
  79. NOTE: curl/cmd.run usage to fetch gpg key has limited functionality behind proxy.
  80. Environments with salt >= 2017.7 should use key_url specified at
  81. pkgrepo.manage state (which uses properly configured http_host at
  82. minion.conf). Older versions of salt require to have proxy set at
  83. ENV and curl way to fetch gpg key here can have a sense for backward
  84. compatibility. Be aware that as of salt 2018.3 no_proxy option is
  85. not implemented at all.
  86. #}
  87. {%- elif repo.key_url|default(False) and grains['saltversioninfo'] < [2017, 7] and not repo.key_url.startswith('salt://') %}
  88. linux_repo_{{ name }}_key:
  89. cmd.run:
  90. - name: "curl -sL {{ repo.key_url }} | apt-key add -"
  91. - require_in:
  92. {%- if repo.get('default', False) %}
  93. - file: default_repo_list
  94. {% else %}
  95. - pkgrepo: linux_repo_{{ name }}
  96. {% endif %}
  97. {%- endif %}
  98. {%- if repo.get('default', False) %}
  99. {%- do default_repos.update({name: repo}) %}
  100. {%- else %}
  101. {%- if repo.get('enabled', True) %}
  102. linux_repo_{{ name }}:
  103. pkgrepo.managed:
  104. - refresh_db: False
  105. - require_in:
  106. - refresh_db
  107. {%- if repo.ppa is defined %}
  108. - ppa: {{ repo.ppa }}
  109. {%- else %}
  110. - humanname: {{ name }}
  111. - name: {{ repo.source }}
  112. {%- if repo.architectures is defined %}
  113. - architectures: {{ repo.architectures }}
  114. {%- endif %}
  115. - file: /etc/apt/sources.list.d/{{ name }}.list
  116. - clean_file: {{ repo.get('clean_file', True) }}
  117. {%- if repo.key_id is defined %}
  118. - keyid: {{ repo.key_id }}
  119. {%- endif %}
  120. {%- if repo.key_server is defined %}
  121. - keyserver: {{ repo.key_server }}
  122. {%- endif %}
  123. {%- if repo.key_url is defined and (grains['saltversioninfo'] >= [2017, 7] or repo.key_url.startswith('salt://')) %}
  124. - key_url: {{ repo.key_url }}
  125. {%- endif %}
  126. - consolidate: {{ repo.get('consolidate', False) }}
  127. - require:
  128. - file: /etc/apt/apt.conf.d/99proxies-salt-{{ name }}
  129. - file: /etc/apt/apt.conf.d/99proxies-salt
  130. {%- if system.purge_repos|default(False) %}
  131. - file: purge_sources_list_d_repos
  132. {%- endif %}
  133. {%- endif %}
  134. {%- else %}
  135. linux_repo_{{ name }}:
  136. pkgrepo.absent:
  137. - refresh_db: False
  138. - require:
  139. - file: /etc/apt/apt.conf.d/99proxies-salt-{{ name }}
  140. - require_in:
  141. - refresh_db
  142. {%- if repo.ppa is defined %}
  143. - ppa: {{ repo.ppa }}
  144. {%- if repo.key_id is defined %}
  145. - keyid_ppa: {{ repo.keyid_ppa }}
  146. {%- endif %}
  147. {%- else %}
  148. - file: /etc/apt/sources.list.d/{{ name }}.list
  149. {%- if repo.key_id is defined %}
  150. - keyid: {{ repo.key_id }}
  151. {%- endif %}
  152. {%- endif %}
  153. {%- endif %}
  154. {%- endif %}
  155. {%- endif %}
  156. {%- if grains.os_family == "RedHat" %}
  157. {%- if repo.get('enabled', True) %}
  158. {%- if repo.get('proxy', {}).get('enabled', False) %}
  159. # PLACEHOLDER
  160. # TODO, implement per proxy configuration for Yum
  161. {%- endif %}
  162. {%- if not repo.get('default', False) %}
  163. linux_repo_{{ name }}:
  164. pkgrepo.managed:
  165. - refresh_db: False
  166. - require_in:
  167. - refresh_db
  168. - name: {{ name }}
  169. - humanname: {{ repo.get('humanname', name) }}
  170. {%- if repo.mirrorlist is defined %}
  171. - mirrorlist: {{ repo.mirrorlist }}
  172. {%- else %}
  173. - baseurl: {{ repo.source }}
  174. {%- endif %}
  175. - gpgcheck: {% if repo.get('gpgcheck', False) %}1{% else %}0{% endif %}
  176. {%- if repo.gpgkey is defined %}
  177. - gpgkey: {{ repo.gpgkey }}
  178. {%- endif %}
  179. {%- endif %}
  180. {%- else %}
  181. pkgrepo.absent:
  182. - refresh_db: False
  183. - require_in:
  184. - refresh_db
  185. - name: {{ repo.source }}
  186. {%- endif %}
  187. {%- endif %}
  188. {%- endfor %}
  189. {%- if default_repos|length > 0 and grains.os_family == 'Debian' %}
  190. default_repo_list:
  191. file.managed:
  192. - name: /etc/apt/sources.list
  193. - source: salt://linux/files/sources.list
  194. - template: jinja
  195. - user: root
  196. - group: root
  197. - mode: 0644
  198. {%- if system.purge_repos|default(False) %}
  199. - replace: True
  200. {%- endif %}
  201. - defaults:
  202. default_repos: {{ default_repos }}
  203. {%- endif %}
  204. refresh_db:
  205. {%- if system.get('refresh_repos_meta', True) %}
  206. module.run:
  207. - name: pkg.refresh_db
  208. {%- else %}
  209. test.succeed_without_changes
  210. {%- endif %}
  211. {%- endif %}