Skip to content

Instantly share code, notes, and snippets.

@thekuffs
Last active January 11, 2020 22:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thekuffs/4115506 to your computer and use it in GitHub Desktop.
Save thekuffs/4115506 to your computer and use it in GitHub Desktop.
Salt: Add repos in Ubuntu
{% if grains['os'] == 'Ubuntu' %}
{% from "pkg_repo/apt.sls" import apt_repo with context %}
{% if pillar['pkg_mirrors_enabled'] %}
{% set mirrors = ['http://' + pillar['pkg_mirror'] + '/10gen/repo/upbuntu-upstart/',
'http://downloads-distro.mongodb.org/repo/ubuntu-upstart/'] %}
{% else %}
{% set mirrors = ['http://downloads-distro.mongodb.org/repo/ubuntu-upstart/'] %}
{% endif %}
{{ apt_repo('10gen', mirrors, codename='dist', components=['10gen'], key_id='7F0CEB10') }}
{% elif grains['os'] == 'Debian' %}
{% from "pkg_repo/apt.sls" import apt_repo with context %}
{% if pillar['pkg_mirrors_enabled'] %}
{% set mirrors = ['http://' + pillar['pkg_mirror'] + '/10gen/repo/debian-sysvinit/',
'http://downloads-distro.mongodb.org/repo/debian-sysvinit/'] %}
{% else %}
{% set mirrors = ['http://downloads-distro.mongodb.org/repo/debian-sysvinit/'] %}
{% endif %}
{{ apt_repo('10gen', mirrors, codename='dist', components=['10gen'], key_id='7F0CEB10') }}
{% endif %}
# new repos need to call apt-get update to refresh the package cache
'apt-update':
cmd.wait:
- name: '/usr/bin/apt-get update'
python-software-properties:
pkg:
- installed
{% macro apt_repo(name, urls, codename=None, components=['main'], types=['deb'],
key_source=None, key_id=None,
keyserver='keyserver.ubuntu.com') -%}
{% if codename == None %}
{% set codename = grains['oscodename'] %}
{% endif %}
# this is a bit of a hack
# This SLS file will only imported as a macro. So in the macro that is
# instantiated, import the non-macro'd parts of this file and add the
# necessary requisites to make sure apt-get update gets called after repo
# refreshes.
include:
- pkg_repo.apt
{% set filename = '/etc/apt/sources.list.d/' + name + '.list' %}
# the actual repo file in /etc/apt/sources.list.d
'pkg_repo.{{ name }}':
file.managed:
- name: '{{ filename }}'
- user: root
- group: root
- template: jinja
- mode: '0644'
- source: 'salt://pkg_repo/templates/apt_repo.jinja'
- context:
types: {{ types }}
urls: {{ urls }}
codename: '{{ codename }}'
components: {{ components }}
- watch_in:
- cmd: 'apt-update'
{% if key_source %}
# if there is a key to download from the master, download it
{% set key_file = '/etc/apt/trusted.gpg.d/' + name + '-repo.gpg' %}
'{{ key_file }}':
file.managed:
- user: root
- group: root
- source: '{{ key_source }}'
- watch_in:
- cmd: 'apt-update'
{% elif key_id %}
# otherwise request the key from the keyserver
'key_import.{{ name }}':
cmd.run:
- name: '/usr/bin/apt-key adv --keyserver {{ keyserver }} --recv {{ key_id }}'
- unless: '/usr/bin/apt-key list | grep {{ key_id }}'
- watch_in:
- cmd: 'apt-update'
{% endif %}
{%- endmacro %}
# Some details taken from https://help.ubuntu.com/community/PinningHowto#Examples
# and http://manpages.ubuntu.com/manpages/lucid/man5/apt_preferences.5.html
{% macro ppa_repo(name) %}
include:
- pkg_repo.apt
{% set shortname = name.replace('/', '-') %}
'pkg_repo.{{ name }}':
cmd.run:
- name: '/usr/bin/add-apt-repository ppa:{{ name }}'
- unless: '/usr/bin/test -f /etc/apt/sources.list.d/{{ shortname }}-{{ grains['oscodename'] }}.list'
- require:
- pkg: python-software-properties
- watch_in:
- cmd: 'apt-update'
'pin_repo.{{ name }}':
file.managed:
- name: '/etc/apt/preferences.d/{{ shortname }}-pin-100'
- source: 'salt://pkg_repo/templates/pin_ppa.jinja'
- template: jinja
- context:
shortname: {{ shortname }}
- watch_in:
- cmd: 'apt-update'
{% endmacro %}
{% for url in urls -%}
{% for type in types %}
{{ type }} {{ url }} {{ codename }} {{ ' '.join(components) }}
{%- endfor %}
{%- endfor %}
Package: *
Pin: release o=LP-PPA-{{ shortname }}
Pin-Priority: 100
{% from "pkg_repo/apt.sls" import ppa_repo with context %}
{{ ppa_repo('raphink/augeas') }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment