diff --git a/CHANGELOG.md b/CHANGELOG.md index 31130c83..610982f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This file is used to list changes made in each version of cookbook-openstack-com * Make default using cinder v2 api * Add OS_VOLUME_API_VERSION for openrc * Removed the hardcoded PPA reference to "Precise" +* Added an optional automatic apt-get update for Debian based repos ## 10.1.0 * Adding identity admin bind host endpoint to allow flexibility and consistency diff --git a/attributes/default.rb b/attributes/default.rb index c1055cb7..cda1d62d 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -108,6 +108,10 @@ default['openstack']['release'] = 'juno' # In the component strings, %codename% will be replaced by the value of # the node['lsb']['codename'] Ohai value and %release% will be replaced # by the value of node['openstack']['release'] +# +# Change ['openstack']['apt']['update_apt_cache'] to true if you would like +# have the cache automaticly updated +default['openstack']['apt']['update_apt_cache'] = false default['openstack']['apt']['live_updates_enabled'] = true default['openstack']['apt']['uri'] = 'http://ubuntu-cloud.archive.canonical.com/ubuntu' default['openstack']['apt']['components'] = ["#{node['lsb']['codename']}-updates/#{node['openstack']['release']}", 'main'] diff --git a/recipes/default.rb b/recipes/default.rb index 3f4e3ac2..f964ee97 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -21,6 +21,10 @@ platform_options = node['openstack']['common']['platform'] case node['platform_family'] when 'debian' + if node['openstack']['apt']['update_apt_cache'] + # Ensure we've done an apt-update first or packages won't be found. + include_recipe 'apt' + end package 'ubuntu-cloud-keyring' do options platform_options['package_overrides'] action :upgrade diff --git a/spec/default_spec.rb b/spec/default_spec.rb index 81067354..98a10ae1 100644 --- a/spec/default_spec.rb +++ b/spec/default_spec.rb @@ -11,6 +11,15 @@ describe 'openstack-common::default' do runner.converge(described_recipe) end + it 'includes apt for apt-get update' do + node.set['openstack']['apt']['update_apt_cache'] = 'true' + expect(chef_run).to include_recipe 'apt' + end + + it 'doesnt include apt for apt-get update' do + expect(chef_run).to_not include_recipe 'apt' + end + it 'upgrades ubuntu-cloud-keyring package' do expect(chef_run).to upgrade_package 'ubuntu-cloud-keyring' end