| 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 | 10462bb | 2017-03-23 19:18:08 +0100 | [diff] [blame] | 4 | # global proxy setup | 
 | 5 | {%- if system.proxy.get('pkg', {}).get('enabled', False) %} | 
 | 6 | {%- if grains.os_family == 'Debian' %} | 
 | 7 |  | 
 | 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 |  | 
 | 18 | {%- else %} | 
 | 19 |  | 
 | 20 | /etc/apt/apt.conf.d/99proxies-salt: | 
 | 21 |   file.absent | 
 | 22 |  | 
 | 23 | {%- endif %} | 
 | 24 | {%- endif %} | 
 | 25 |  | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 26 | {% set default_repos = {} %} | 
 | 27 |  | 
 | 28 | {%- for name, repo in system.repo.iteritems() %} | 
 | 29 |  | 
 | 30 | {%- if grains.os_family == 'Debian' %} | 
 | 31 |  | 
| Petr Michalec | 10462bb | 2017-03-23 19:18:08 +0100 | [diff] [blame] | 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 |  | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 49 | {%- if repo.pin is defined %} | 
 | 50 |  | 
 | 51 | linux_repo_{{ name }}_pin: | 
 | 52 |   file.managed: | 
 | 53 |     - name: /etc/apt/preferences.d/{{ name }} | 
 | 54 |     - source: salt://linux/files/preferences_repo | 
 | 55 |     - template: jinja | 
 | 56 |     - defaults: | 
 | 57 |         repo_name: {{ name }} | 
 | 58 |  | 
 | 59 | {%- else %} | 
 | 60 |  | 
 | 61 | linux_repo_{{ name }}_pin: | 
 | 62 |   file.absent: | 
 | 63 |     - name: /etc/apt/preferences.d/{{ name }} | 
 | 64 |  | 
 | 65 | {%- endif %} | 
 | 66 |  | 
 | 67 | {%- if repo.get('default', False) %} | 
 | 68 |  | 
 | 69 | {%- do default_repos.update({name: repo}) %} | 
 | 70 |  | 
| Filip Pytloun | d147ae1 | 2016-08-30 15:44:46 +0200 | [diff] [blame] | 71 | {%- if repo.key_url|default(False) %} | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 72 |  | 
 | 73 | linux_repo_{{ name }}_key: | 
 | 74 |   cmd.wait: | 
 | 75 |     - name: "curl -s {{ repo.key_url }} | apt-key add -" | 
 | 76 |     - watch: | 
 | 77 |       - file: default_repo_list | 
 | 78 |  | 
 | 79 | {%- endif %} | 
 | 80 |  | 
 | 81 | {%- else %} | 
 | 82 |  | 
 | 83 | linux_repo_{{ name }}: | 
 | 84 |   pkgrepo.managed: | 
 | 85 |   - human_name: {{ name }} | 
 | 86 |   - name: {{ repo.source }} | 
 | 87 |   {%- if repo.architectures is defined %} | 
 | 88 |   - architectures: {{ repo.architectures }} | 
 | 89 |   {%- endif %} | 
 | 90 |   - file: /etc/apt/sources.list.d/{{ name }}.list | 
| Filip Pytloun | 914eff9 | 2017-03-22 18:46:15 +0100 | [diff] [blame^] | 91 |   - clean_file: {{ repo.clean|default(True) }} | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 92 |   {%- if repo.key_id is defined %} | 
 | 93 |   - keyid: {{ repo.key_id }} | 
 | 94 |   {%- endif %} | 
 | 95 |   {%- if repo.key_server is defined %} | 
 | 96 |   - keyserver: {{ repo.key_server }} | 
 | 97 |   {%- endif %} | 
 | 98 |   {%- if repo.key_url is defined %} | 
 | 99 |   - key_url: {{ repo.key_url }} | 
 | 100 |   {%- endif %} | 
| Petr Michalec | c146f18 | 2017-03-22 10:14:32 +0100 | [diff] [blame] | 101 |   - consolidate: {{ repo.get('consolidate', False) }} | 
 | 102 |   - clean_file: {{ repo.get('clean_file', False) }} | 
 | 103 |   - refresh_db: {{ repo.get('refresh_db', True) }} | 
| Marek Celoud | 159d381 | 2017-03-03 23:02:45 +0100 | [diff] [blame] | 104 |   - require: | 
 | 105 |     - pkg: linux_packages | 
| Petr Michalec | 10462bb | 2017-03-23 19:18:08 +0100 | [diff] [blame] | 106 |   {%- if repo.get('proxy', {}).get('enabled', False) %} | 
 | 107 |     - file: /etc/apt/apt.conf.d/99proxies-salt-{{ name }} | 
 | 108 |   {%- endif %} | 
 | 109 |   {%- if system.proxy.get('pkg', {}).get('enabled', False) %} | 
 | 110 |     - file: /etc/apt/apt.conf.d/99proxies-salt | 
 | 111 |   {%- endif %} | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 112 |  | 
 | 113 | {%- endif %} | 
 | 114 |  | 
 | 115 | {%- endif %} | 
 | 116 |  | 
 | 117 | {%- if grains.os_family == "RedHat" %} | 
 | 118 |  | 
| Petr Michalec | 10462bb | 2017-03-23 19:18:08 +0100 | [diff] [blame] | 119 | {%- if repo.get('proxy', {}).get('enabled', False) %} | 
 | 120 | # PLACEHOLDER | 
 | 121 | # TODO, implement per proxy configuration for Yum | 
 | 122 | {%- endif %} | 
 | 123 |  | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 124 | {%- if not repo.get('default', False) %} | 
 | 125 |  | 
 | 126 | linux_repo_{{ name }}: | 
 | 127 |   pkgrepo.managed: | 
 | 128 |   - name: {{ name }} | 
| Filip Pytloun | 96be437 | 2016-03-19 14:02:47 +0100 | [diff] [blame] | 129 |   - humanname: {{ repo.get('humanname', name) }} | 
 | 130 |   {%- if repo.mirrorlist is defined %} | 
 | 131 |   - mirrorlist: {{ repo.mirrorlist }} | 
 | 132 |   {%- else %} | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 133 |   - baseurl: {{ repo.source }} | 
| Filip Pytloun | 96be437 | 2016-03-19 14:02:47 +0100 | [diff] [blame] | 134 |   {%- endif %} | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 135 |   - gpgcheck: {% if repo.get('gpgcheck', False) %}1{% else %}0{% endif %} | 
| Filip Pytloun | 96be437 | 2016-03-19 14:02:47 +0100 | [diff] [blame] | 136 |   {%- if repo.gpgkey is defined %} | 
 | 137 |   - gpgkey: {{ repo.gpgkey }} | 
 | 138 |   {%- endif %} | 
| Marek Celoud | 159d381 | 2017-03-03 23:02:45 +0100 | [diff] [blame] | 139 |   - require: | 
 | 140 |     - pkg: linux_packages | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 141 |  | 
 | 142 | {%- endif %} | 
 | 143 |  | 
 | 144 | {%- endif %} | 
 | 145 |  | 
 | 146 | {%- endfor %} | 
 | 147 |  | 
 | 148 | {%- if default_repos|length > 0 and grains.os_family == 'Debian' %} | 
 | 149 |  | 
 | 150 | default_repo_list: | 
 | 151 |   file.managed: | 
 | 152 |     - name: /etc/apt/sources.list | 
 | 153 |     - source: salt://linux/files/sources.list | 
 | 154 |     - template: jinja | 
 | 155 |     - user: root | 
 | 156 |     - group: root | 
 | 157 |     - mode: 0644 | 
 | 158 |     - defaults: | 
 | 159 |         default_repos: {{ default_repos }} | 
| Marek Celoud | 159d381 | 2017-03-03 23:02:45 +0100 | [diff] [blame] | 160 |     - require: | 
 | 161 |       - pkg: linux_packages | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 162 |  | 
 | 163 | {%- endif %} | 
 | 164 |  | 
 | 165 | {%- endif %} |