Selaa lähdekoodia

Add state file to manage repositories

master
Javier Bértoli 8 vuotta sitten
vanhempi
commit
54583ed5c0
3 muutettua tiedostoa jossa 82 lisäystä ja 2 poistoa
  1. +22
    -0
      apt/map.jinja
  2. +56
    -0
      apt/repositories.sls
  3. +4
    -2
      apt/upgrade.sls

+ 22
- 0
apt/map.jinja Näytä tiedosto

@@ -1,8 +1,30 @@
{% set distribution = salt['grains.get']('lsb_distrib_codename') %}
{% set distribution_updates = salt['grains.get']('lsb_distrib_codename') ~ '/updates' %}
{% set arch = salt['grains.get']('osarch').split(' ') %}
{% set apt = salt['grains.filter_by']({
'Debian': {
'pkgs': ['unattended-upgrades'],
'confd_dir': '/etc/apt/apt.conf.d',
'unattended_config': '50unattended-upgrades',
'periodic_config': '10periodic',
'sources_list_dir': '/etc/apt/sources.list.d',
'remove_sources_list': false,
'clean_sources_list_d': false,
'default_url': 'http://httpredir.debian.org/debian/',
'repositories': {
'sane_default': {
'distro': distribution,
'url': 'http://httpredir.debian.org/debian/',
'arch': arch,
'comps': ['main'],
},
'security-stable': {
'distro': distribution_updates,
'url': 'http://security.debian.org/',
'arch': arch,
'comps': ['main'],
},
},
},
}, merge=salt['pillar.get']('apt:lookup'), default='Debian') %}


+ 56
- 0
apt/repositories.sls Näytä tiedosto

@@ -0,0 +1,56 @@
{% from "apt/map.jinja" import apt as apt_map with context %}
{% set apt = pillar.get('apt', {}) %}
{% set remove_sources_list = apt.get('remove_sources_list', apt_map.remove_sources_list) %}
{% set clean_sources_list_d = apt.get('clean_sources_list_d', apt_map.clean_sources_list_d) %}
{% set sources_list_dir = apt.get('sources_list_dir', apt_map.sources_list_dir) %}
{% set repositories = apt.get('repositories', apt_map.repositories) %}
{% set default_url = apt.get('default_url', apt_map.default_url) %}

debian-archive-keyring:
pkg.installed

/etc/apt/sources.list:
{% if remove_sources_list %}
file.absent
{% else %}
file.managed:
- mode: 0644
- user: root
- group: root
{% endif %}

{{ sources_list_dir }}:
file.directory:
- mode: 0755
- user: root
- group: root
- clean: {{ clean_sources_list_d }}

{% for repo, args in repositories.iteritems() %}
{%- set r_arch = '[arch=' ~ args.arch|join(',') ~ ']' if args.arch is defined else '' %}
{%- set r_url = args.url or default_url %}
{%- set r_distro = args.distro or 'stable' %}
{%- set r_comps = args.comps|default(['main'])|join(' ') %}

{%- if "binary" in args.type|d(["binary"]) %}
{{ repo }}:
pkgrepo.managed:
- name: deb {{ r_arch }} {{ r_url }} {{ r_distro }} {{ r_comps }}
- file: {{ sources_list_dir }}/{{ repo }}.list
{% if args.key_url is defined %}
- key_url: {{ args.key_url }}
{% endif %}
- clean_file: true
{% endif %}

{%- if "source" in args.type|d(["binary"]) %}
{{ repo }}:
pkgrepo.managed:
- name: deb-src {{ r_arch }} {{ r_url }} {{ r_distro }} {{ r_comps }}
- file: {{ sources_list_dir }}/{{ repo }}.list
{% if args.key_url is defined %}
- key_url: {{ args.key_url }}
{% endif %}
- clean_file: true
{% endif %}
{% endfor %}

+ 4
- 2
apt/upgrade.sls Näytä tiedosto

@@ -1,3 +1,5 @@
apt-get upgrade:
cmd:
- run
cmd.wait:
- watch:
- file: /etc/apt/sources.list
- file: /etc/apt/sources.list.d

Loading…
Peruuta
Tallenna