Skip to content

Commit

Permalink
[debops.apt] Allow sources to be overridden in inventory.
Browse files Browse the repository at this point in the history
Before this, there was no good way to override apt__security_sources
and apt__default_sources, without copying the entire variables to your
inventory.
This may be beneficial when you want to use a local mirror instead
of the public mirrors.
  • Loading branch information
tumd committed Dec 11, 2018
1 parent 6227cb0 commit 1af4528
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
53 changes: 47 additions & 6 deletions ansible/roles/debops.apt/defaults/main.yml
Expand Up @@ -355,6 +355,19 @@ apt__original_sources:
ansible_local.apt.original_mirrors_deb|d())
else "absent" }}'

# ]]]
# .. envvar:: apt__default_sources_present [[[
#
# Define if the default APT package sources for specific distributions should
# be used or not.
# If package sources are defined in specific group, host or on all hosts in
# Ansible inventory, the default sources will be disabled.
apt__default_sources_present: '{{ "True"
if ( not apt__group_sources and
not apt__host_sources and
not apt__sources )
else "False" }}'

# ]]]
# .. envvar:: apt__default_sources [[[
#
Expand Down Expand Up @@ -405,6 +418,32 @@ apt__default_sources:
comment: '{{ "Official " + apt__distribution + " repositories" }}'
distribution: 'Devuan'

# ]]]
# .. envvar:: apt__security_sources_state [[[
#
# Enable (if ``present``) or disable (if ``absent``) the default APT
# repositories proving security updates.
# If a local security mirror is defined in Ansible inventory group or host,
# this will disable the default security repositories.
apt__security_sources_state: '{{ "present"
if ( not apt__group_security_sources and
not apt__host_security_sources )
else "absent" }}'

# ]]]
# .. envvar:: apt__group_security_sources [[[
#
# List of APT repositories that provide security updates for hosts in
# specific Ansible inventory group.
apt__group_security_sources: []

# ]]]
# .. envvar:: apt__host_security_sources [[[
#
# List of APT repositories that provide security updates for hosts in
# specific Ansible inventory host.
apt__host_security_sources: []

# ]]]
# .. envvar:: apt__security_sources [[[
#
Expand All @@ -419,7 +458,7 @@ apt__security_sources:
suite: '{{ apt__distribution_release + "/updates" }}'
components: '{{ apt__distribution_components }}'
distribution: 'Debian'
state: '{{ "present"
state: '{{ apt__security_sources_state
if (apt__distribution_release|d("unknown")
in apt__distribution_release_map[apt__distribution]|d([]))
else "absent" }}'
Expand Down Expand Up @@ -451,7 +490,7 @@ apt__security_sources:
suite: '{{ apt__distribution_release + "-security" }}'
components: '{{ apt__distribution_components }}'
distribution: 'Ubuntu'
state: '{{ "present"
state: '{{ apt__security_sources_state
if (apt__architecture in ["amd64", "i386"])
else "absent" }}'

Expand All @@ -461,7 +500,7 @@ apt__security_sources:
suite: '{{ apt__distribution_release + "-security" }}'
components: '{{ apt__distribution_components }}'
distribution: 'Ubuntu'
state: '{{ "present"
state: '{{ apt__security_sources_state
if (apt__architecture not in ["amd64", "i386"])
else "absent" }}'

Expand All @@ -471,7 +510,7 @@ apt__security_sources:
suite: '{{ apt__distribution_release + "-security" }}'
components: '{{ apt__distribution_components }}'
distribution: 'Devuan'
state: '{{ "present"
state: '{{ apt__security_sources_state
if (apt__distribution_release|d("unknown")
in apt__distribution_release_map[apt__distribution]|d([]))
else "absent" }}'
Expand All @@ -485,8 +524,10 @@ apt__security_sources:
apt__combined_sources: '{{ apt__sources +
apt__group_sources +
apt__host_sources +
apt__original_sources +
apt__default_sources +
apt__original_sources }} +
{{ apt__default_sources if apt__default_sources_present else [] }} +
{{ apt__host_security_sources +
apt__group_security_sources +
apt__security_sources }}'
# ]]]
# ]]]
Expand Down
Expand Up @@ -15,7 +15,7 @@ import os
{% set apt__tpl_default_sources = [] %}
{% set apt__tpl_default_sources_map = {} %}
{% set apt__tpl_source_distributions = {} %}
{% for repo in apt__security_sources %}
{% for repo in ( apt__host_security_sources, apt__group_security_sources, apt__security_sources ) %}
{% set _ = apt__tpl_security_sources.extend(
debops__tpl_macros.flattened(
repo.uri, repo.uris) | from_json) %}
Expand Down

0 comments on commit 1af4528

Please sign in to comment.