Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 1 | {%- from "linux/map.jinja" import system with context %} |
| 2 | {%- if system.enabled %} |
| 3 | |
Petr Michalec | 459da2b | 2017-04-13 11:13:09 +0200 | [diff] [blame] | 4 | linux_repo_prereq_pkgs: |
| 5 | pkg.installed: |
| 6 | - pkgs: {{ system.pkgs }} |
Marek Celoud | 9ed3403 | 2017-04-11 16:03:23 +0200 | [diff] [blame] | 7 | |
Petr Michalec | 10462bb | 2017-03-23 19:18:08 +0100 | [diff] [blame] | 8 | # global proxy setup |
| 9 | {%- if system.proxy.get('pkg', {}).get('enabled', False) %} |
| 10 | {%- if grains.os_family == 'Debian' %} |
| 11 | |
| 12 | /etc/apt/apt.conf.d/99proxies-salt: |
| 13 | file.managed: |
| 14 | - template: jinja |
| 15 | - source: salt://linux/files/apt.conf.d_proxies |
| 16 | - defaults: |
| 17 | external_host: False |
| 18 | https: {{ system.proxy.get('pkg', {}).get('https', None) | default(system.proxy.get('https', None), true) }} |
| 19 | http: {{ system.proxy.get('pkg', {}).get('http', None) | default(system.proxy.get('http', None), true) }} |
| 20 | ftp: {{ system.proxy.get('pkg', {}).get('ftp', None) | default(system.proxy.get('ftp', None), true) }} |
| 21 | |
| 22 | {%- else %} |
| 23 | |
| 24 | /etc/apt/apt.conf.d/99proxies-salt: |
| 25 | file.absent |
| 26 | |
| 27 | {%- endif %} |
| 28 | {%- endif %} |
| 29 | |
Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 30 | {% set default_repos = {} %} |
| 31 | |
Jiri Broulik | 25839cc | 2017-04-18 17:05:20 +0200 | [diff] [blame] | 32 | {%- if system.purge_repos|default(False) %} |
| 33 | |
| 34 | purge_sources_list_d_repos: |
| 35 | file.directory: |
| 36 | - name: /etc/apt/sources.list.d/ |
| 37 | - clean: True |
| 38 | |
| 39 | {%- endif %} |
| 40 | |
Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 41 | {%- for name, repo in system.repo.iteritems() %} |
| 42 | |
| 43 | {%- if grains.os_family == 'Debian' %} |
| 44 | |
Petr Michalec | 10462bb | 2017-03-23 19:18:08 +0100 | [diff] [blame] | 45 | # per repository proxy setup |
| 46 | {%- if repo.get('proxy', {}).get('enabled', False) %} |
| 47 | {%- set external_host = repo.proxy.get('host', None) or repo.source.split('/')[2] %} |
| 48 | /etc/apt/apt.conf.d/99proxies-salt-{{ name }}: |
| 49 | file.managed: |
| 50 | - template: jinja |
| 51 | - source: salt://linux/files/apt.conf.d_proxies |
| 52 | - defaults: |
| 53 | external_host: {{ external_host }} |
| 54 | https: {{ repo.proxy.get('https', None) or system.proxy.get('pkg', {}).get('https', None) | default(system.proxy.get('https', None), True) }} |
| 55 | http: {{ repo.proxy.get('http', None) or system.proxy.get('pkg', {}).get('http', None) | default(system.proxy.get('http', None), True) }} |
| 56 | ftp: {{ repo.proxy.get('ftp', None) or system.proxy.get('pkg', {}).get('ftp', None) | default(system.proxy.get('ftp', None), True) }} |
| 57 | {%- else %} |
| 58 | /etc/apt/apt.conf.d/99proxies-salt-{{ name }}: |
| 59 | file.absent |
| 60 | {%- endif %} |
| 61 | |
Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 62 | {%- if repo.pin is defined %} |
| 63 | |
| 64 | linux_repo_{{ name }}_pin: |
| 65 | file.managed: |
| 66 | - name: /etc/apt/preferences.d/{{ name }} |
| 67 | - source: salt://linux/files/preferences_repo |
| 68 | - template: jinja |
| 69 | - defaults: |
| 70 | repo_name: {{ name }} |
| 71 | |
| 72 | {%- else %} |
| 73 | |
| 74 | linux_repo_{{ name }}_pin: |
| 75 | file.absent: |
| 76 | - name: /etc/apt/preferences.d/{{ name }} |
| 77 | |
| 78 | {%- endif %} |
| 79 | |
| 80 | {%- if repo.get('default', False) %} |
| 81 | |
| 82 | {%- do default_repos.update({name: repo}) %} |
| 83 | |
Petr Michalec | 1ae62b1 | 2017-04-27 14:35:13 +0200 | [diff] [blame] | 84 | {%- if repo.get('key') %} |
| 85 | |
| 86 | linux_repo_{{ name }}_key: |
| 87 | cmd.wait: |
| 88 | - name: "echo '{{ repo.key }}' | apt-key add -" |
| 89 | - watch: |
| 90 | - file: default_repo_list |
| 91 | |
| 92 | {%- elif repo.key_url|default(False) %} |
Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 93 | |
| 94 | linux_repo_{{ name }}_key: |
| 95 | cmd.wait: |
| 96 | - name: "curl -s {{ repo.key_url }} | apt-key add -" |
| 97 | - watch: |
| 98 | - file: default_repo_list |
| 99 | |
| 100 | {%- endif %} |
| 101 | |
| 102 | {%- else %} |
| 103 | |
| 104 | linux_repo_{{ name }}: |
| 105 | pkgrepo.managed: |
Martin Polreich | 09a648a | 2017-05-04 11:35:14 +0200 | [diff] [blame] | 106 | {%- if repo.ppa is defined %} |
| 107 | - ppa: {{ ppa }} |
| 108 | {%- else %} |
Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 109 | - human_name: {{ name }} |
| 110 | - name: {{ repo.source }} |
| 111 | {%- if repo.architectures is defined %} |
| 112 | - architectures: {{ repo.architectures }} |
| 113 | {%- endif %} |
| 114 | - file: /etc/apt/sources.list.d/{{ name }}.list |
Filip Pytloun | 914eff9 | 2017-03-22 18:46:15 +0100 | [diff] [blame] | 115 | - clean_file: {{ repo.clean|default(True) }} |
Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 116 | {%- if repo.key_id is defined %} |
| 117 | - keyid: {{ repo.key_id }} |
| 118 | {%- endif %} |
| 119 | {%- if repo.key_server is defined %} |
| 120 | - keyserver: {{ repo.key_server }} |
| 121 | {%- endif %} |
| 122 | {%- if repo.key_url is defined %} |
| 123 | - key_url: {{ repo.key_url }} |
| 124 | {%- endif %} |
Petr Michalec | c146f18 | 2017-03-22 10:14:32 +0100 | [diff] [blame] | 125 | - consolidate: {{ repo.get('consolidate', False) }} |
| 126 | - clean_file: {{ repo.get('clean_file', False) }} |
| 127 | - refresh_db: {{ repo.get('refresh_db', True) }} |
Marek Celoud | 159d381 | 2017-03-03 23:02:45 +0100 | [diff] [blame] | 128 | - require: |
Petr Michalec | 459da2b | 2017-04-13 11:13:09 +0200 | [diff] [blame] | 129 | - pkg: linux_repo_prereq_pkgs |
Petr Michalec | 10462bb | 2017-03-23 19:18:08 +0100 | [diff] [blame] | 130 | {%- if repo.get('proxy', {}).get('enabled', False) %} |
| 131 | - file: /etc/apt/apt.conf.d/99proxies-salt-{{ name }} |
| 132 | {%- endif %} |
| 133 | {%- if system.proxy.get('pkg', {}).get('enabled', False) %} |
| 134 | - file: /etc/apt/apt.conf.d/99proxies-salt |
| 135 | {%- endif %} |
Jiri Broulik | 25839cc | 2017-04-18 17:05:20 +0200 | [diff] [blame] | 136 | {%- if system.purge_repos|default(False) %} |
| 137 | - file: purge_sources_list_d_repos |
| 138 | {%- endif %} |
Martin Polreich | 09a648a | 2017-05-04 11:35:14 +0200 | [diff] [blame] | 139 | {%- endif %} |
Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 140 | |
| 141 | {%- endif %} |
| 142 | |
| 143 | {%- endif %} |
| 144 | |
| 145 | {%- if grains.os_family == "RedHat" %} |
| 146 | |
Petr Michalec | 10462bb | 2017-03-23 19:18:08 +0100 | [diff] [blame] | 147 | {%- if repo.get('proxy', {}).get('enabled', False) %} |
| 148 | # PLACEHOLDER |
| 149 | # TODO, implement per proxy configuration for Yum |
| 150 | {%- endif %} |
| 151 | |
Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 152 | {%- if not repo.get('default', False) %} |
| 153 | |
| 154 | linux_repo_{{ name }}: |
| 155 | pkgrepo.managed: |
| 156 | - name: {{ name }} |
Filip Pytloun | 96be437 | 2016-03-19 14:02:47 +0100 | [diff] [blame] | 157 | - humanname: {{ repo.get('humanname', name) }} |
| 158 | {%- if repo.mirrorlist is defined %} |
| 159 | - mirrorlist: {{ repo.mirrorlist }} |
| 160 | {%- else %} |
Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 161 | - baseurl: {{ repo.source }} |
Filip Pytloun | 96be437 | 2016-03-19 14:02:47 +0100 | [diff] [blame] | 162 | {%- endif %} |
Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 163 | - gpgcheck: {% if repo.get('gpgcheck', False) %}1{% else %}0{% endif %} |
Filip Pytloun | 96be437 | 2016-03-19 14:02:47 +0100 | [diff] [blame] | 164 | {%- if repo.gpgkey is defined %} |
| 165 | - gpgkey: {{ repo.gpgkey }} |
| 166 | {%- endif %} |
Marek Celoud | 159d381 | 2017-03-03 23:02:45 +0100 | [diff] [blame] | 167 | - require: |
Petr Michalec | 459da2b | 2017-04-13 11:13:09 +0200 | [diff] [blame] | 168 | - pkg: linux_repo_prereq_pkgs |
Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 169 | |
| 170 | {%- endif %} |
| 171 | |
| 172 | {%- endif %} |
| 173 | |
| 174 | {%- endfor %} |
| 175 | |
| 176 | {%- if default_repos|length > 0 and grains.os_family == 'Debian' %} |
| 177 | |
| 178 | default_repo_list: |
| 179 | file.managed: |
| 180 | - name: /etc/apt/sources.list |
| 181 | - source: salt://linux/files/sources.list |
| 182 | - template: jinja |
| 183 | - user: root |
| 184 | - group: root |
| 185 | - mode: 0644 |
Jiri Broulik | 25839cc | 2017-04-18 17:05:20 +0200 | [diff] [blame] | 186 | {%- if system.purge_repos %} |
| 187 | - replace: True |
| 188 | {%- endif %} |
Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 189 | - defaults: |
| 190 | default_repos: {{ default_repos }} |
Marek Celoud | 159d381 | 2017-03-03 23:02:45 +0100 | [diff] [blame] | 191 | - require: |
Petr Michalec | 459da2b | 2017-04-13 11:13:09 +0200 | [diff] [blame] | 192 | - pkg: linux_repo_prereq_pkgs |
Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 193 | |
| 194 | {%- endif %} |
| 195 | |
| 196 | {%- endif %} |