Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Debian #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@
default['unattended-upgrades']['automatic_reboot'] = false
default['unattended-upgrades']['download_limit'] = nil # Set to Integer representing kb/sec limit

default['unattended-upgrades']['allowed_origins'] = {
'security' => true,
'updates' => false,
'proposed' => false,
'backports' => false
}
case node['platform']
when 'ubuntu'
default['unattended-upgrades']['allowed_origins'] = {
'security' => true,
'updates' => false,
'proposed' => false,
'backports' => false
}
default['unattended-upgrades']['origin_patterns'] = {}
when 'debian'
default['unattended-upgrades']['allowed_origins'] = {}
default['unattended-upgrades']['origin_patterns'] = {
'origin=Debian,archive=stable,label=Debian-Security' => true
}
end

default['unattended-upgrades']['apt_recipe'] = 'default'

Expand Down
4 changes: 2 additions & 2 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
license "Apache 2.0"
description "Installs/Configures unattended-upgrades"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.1.2"
version "0.2.0"

# supports "debian" # Untested
supports "debian"
supports "ubuntu"

depends "apt"
Expand Down
1 change: 1 addition & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
mode '0644'
variables(
:allowed_origins => node['unattended-upgrades']['allowed_origins'],
:origin_patterns => node['unattended-upgrades']['origin_patterns'],
:package_blacklist => node['unattended-upgrades']['package_blacklist'],
:autofix_dpkg => node['unattended-upgrades']['autofix_dpkg'],
:minimal_steps => node['unattended-upgrades']['minimal_steps'],
Expand Down
24 changes: 20 additions & 4 deletions spec/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@
end

it 'should write the config files' do
expect(chef_run).to render_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content('Unattended-Upgrade::Mail "root@localhost"')
expect(chef_run).to render_file('/etc/apt/apt.conf.d/20auto-upgrades').with_content('APT::Periodic::Unattended-Upgrade "1"')
expect(chef_run).to render_file('/etc/apt/apt.conf.d/50unattended-upgrades')
.with_content('Unattended-Upgrade::Mail "root@localhost"')
expect(chef_run).to render_file('/etc/apt/apt.conf.d/50unattended-upgrades')
.with_content('Unattended-Upgrade::Allowed-Origins')
expect(chef_run).to_not render_file('/etc/apt/apt.conf.d/50unattended-upgrades')
.with_content('Unattended-Upgrade::Origins-Pattern')
expect(chef_run).to render_file('/etc/apt/apt.conf.d/50unattended-upgrades')
.with_content('"${distro_id}:${distro_codename}-security"')
expect(chef_run).to render_file('/etc/apt/apt.conf.d/20auto-upgrades')
.with_content('APT::Periodic::Unattended-Upgrade "1"')
end

it 'should not warn about missing mail package' do
Expand All @@ -41,8 +49,16 @@
end

it 'should write the config files' do
expect(chef_run).to render_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content('Unattended-Upgrade::Mail')
expect(chef_run).to render_file('/etc/apt/apt.conf.d/20auto-upgrades').with_content('APT::Periodic::Unattended-Upgrade "1"')
expect(chef_run).to render_file('/etc/apt/apt.conf.d/50unattended-upgrades').
with_content('Unattended-Upgrade::Mail')
expect(chef_run).to_not render_file('/etc/apt/apt.conf.d/50unattended-upgrades')
.with_content('Unattended-Upgrade::Allowed-Origins')
expect(chef_run).to render_file('/etc/apt/apt.conf.d/50unattended-upgrades')
.with_content('Unattended-Upgrade::Origins-Pattern')
expect(chef_run).to render_file('/etc/apt/apt.conf.d/50unattended-upgrades')
.with_content('origin=Debian,archive=stable,label=Debian-Security')
expect(chef_run).to render_file('/etc/apt/apt.conf.d/20auto-upgrades')
.with_content('APT::Periodic::Unattended-Upgrade "1"')
end
end

Expand Down
15 changes: 14 additions & 1 deletion templates/default/unattended-upgrades.conf.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
// File configured by chef - don't edit manually

<% unless @allowed_origins.empty? %>
// Automatically upgrade packages from these (origin:archive) pairs
Unattended-Upgrade::Allowed-Origins {
<% @allowed_origins.each do |origin, enabled| %>
<%= '//' unless enabled %> "${distro_id}:${distro_codename}-<%= origin %>";
<%= "\"${distro_id}:${distro_codename}-#{origin}\";" if enabled -%>
<% end %>

};
<% end %>

<% unless @origin_patterns.empty? %>
// Automatically upgrade packages from these origin patterns
Unattended-Upgrade::Origins-Pattern {
<% @origin_patterns.each do |pattern, enabled| %>
<%= "\"#{pattern}\";" if enabled -%>
<% end %>

};
<% end %>

// List of packages to not update
Unattended-Upgrade::Package-Blacklist {
Expand Down