├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── Vagrantfile ├── defaults └── main.yml ├── meta └── main.yml ├── tasks └── main.yml ├── templates ├── etc_apt_apt.conf.d_10general.j2 └── etc_apt_sources.list.j2 ├── test.yml ├── vagrant-inventory └── version /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .AppleDouble 3 | .LSOverride 4 | Icon 5 | ._* 6 | .Spotlight-V100 7 | .Trashes 8 | .vagrant 9 | test 10 | .history 11 | .vscode 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: python 3 | python: "2.7" 4 | env: 5 | matrix: 6 | - ANSIBLE_VERSION="2.3" 7 | - ANSIBLE_VERSION="2.7.0" 8 | before_install: 9 | - sudo apt-get update -qq 10 | - sudo apt-get install -qq python-apt python-pycurl 11 | install: 12 | - pip install ansible=="$ANSIBLE_VERSION" 13 | script: 14 | - echo localhost > inventory 15 | - ansible-playbook -i inventory test.yml --syntax-check 16 | - ansible-playbook -i inventory test.yml --connection=local --become 17 | - > 18 | ansible-playbook -i inventory test.yml --connection=local --become 19 | | grep -q 'changed=0.*failed=0' 20 | && (echo 'Idempotence test: pass' && exit 0) 21 | || (echo 'Idempotence test: fail' && exit 1) 22 | notifications: 23 | webhooks: https://galaxy.ansible.com/api/v1/notifications/ 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2014 Pieterjan Vandaele 4 | Copyright (c) 2015-2018 Jonathan E Freedman 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## ANXS - apt [![Build Status](https://travis-ci.com/ANXS/apt.png)](https://travis-ci.com/ANXS/apt) 2 | 3 | Ansible role which executes apt-get update to ensure the local APT package cache is up to date. At the same time, it cleans it from packages and .deb files which are no longer needed. 4 | 5 | 6 | #### Variables 7 | 8 | ```yaml 9 | apt_reset_source_list: no # reset the /etc/apt/sources.list to the default 10 | apt_mirror_url: http://us.archive.ubuntu.com # the mirror from where to install packages 11 | apt_cache_valid_time: 3600 # Time (in seconds) the apt cache stays valid 12 | apt_install_recommends: no # whether or not to install the "recommended" packages 13 | apt_install_suggests: no # whether or not to install the "suggested" packages 14 | apt_autoremove: yes # remove packages that are no longer needed for dependencies 15 | apt_autoremove_recommends: yes # whether to automatically remove "recommended" packages 16 | apt_autoremove_suggests: yes # whether to automatically remove "suggested" packages 17 | apt_autoclean: yes # remove .deb files for packages no longer on your system 18 | apt_default_packages: 19 | - python-apt 20 | - unattended-upgrades 21 | ``` 22 | 23 | Remark: Beware that setting `apt_install_recommends` and `apt_install_suggests` to `yes` may heavily increase the apt-requirements (and hence disk usage). You should proceed cautiously changing these. Similarly, `apt_autoremove_recommends` and `apt_autoremove_suggests` to `no` will make it harder to clean up. 24 | 25 | 26 | #### Testing 27 | This project comes with a VagrantFile, this is a fast and easy way to test changes to the role, fire it up with `vagrant up` 28 | 29 | See [vagrant docs](https://docs.vagrantup.com/v2/) for getting setup with vagrant 30 | 31 | 32 | #### License 33 | 34 | Licensed under the MIT License. See the LICENSE file for details. 35 | 36 | 37 | #### Feedback, bug-reports, requests, ... 38 | 39 | Are [welcome](https://github.com/ANXS/apt/issues)! 40 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant.configure('2') do |config| 5 | config.vm.define 'anxs' do |c| 6 | c.vm.box = 'ubuntu/trusty64' 7 | c.vm.network :private_network, ip: '192.168.88.29' 8 | c.vm.hostname = 'anxs.local' 9 | c.vm.provision 'ansible' do |ansible| 10 | ansible.playbook = 'test.yml' 11 | ansible.sudo = true 12 | ansible.inventory_path = 'vagrant-inventory' 13 | ansible.host_key_checking = false 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | # file: apt/defaults/main.yml 2 | 3 | apt_reset_source_list: no # reset the /etc/apt/sources.list to the default 4 | apt_mirror_url: http://archive.ubuntu.com # the mirror from where to install packages 5 | apt_cache_valid_time: 3600 # Time (in seconds) the apt cache stays valid 6 | apt_install_recommends: no # whether or not to install the "recommended" packages 7 | apt_install_suggests: no # whether or not to install the "suggested" packages 8 | apt_autoremove: yes # remove packages that are no longer needed for dependencies 9 | apt_clean: no # remove all cached .deb files 10 | apt_autoremove_recommends: yes # whether to automatically remove "recommended" packages 11 | apt_autoremove_suggests: yes # whether to automatically remove "suggested" packages 12 | apt_autoclean: yes # remove .deb files for packages no longer on your system 13 | apt_default_packages: 14 | - python3-apt 15 | - unattended-upgrades 16 | - apt-transport-https 17 | - curl 18 | - ca-certificates 19 | - software-properties-common 20 | apt_default_packages_post20: 21 | - python3-apt 22 | apt_default_packages_pre20: 23 | - python-apt 24 | apt_release: jammy # What release to pull from -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | # file: apt/meta/main.yml 2 | 3 | galaxy_info: 4 | author: pjan vandaele 5 | company: ANXS 6 | description: Manages apt and executes apt-get update to ensure the local APT package cache is up to date. 7 | min_ansible_version: 2.3 8 | license: MIT 9 | platforms: 10 | - name: Ubuntu 11 | versions: 12 | - all 13 | categories: 14 | - system 15 | 16 | dependencies: [] 17 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | # file: apt/tasks/main.yml 2 | 3 | - name: APT | Reset the sources list (/etc/apt/sources.list) 4 | template: 5 | src: etc_apt_sources.list.j2 6 | dest: /etc/apt/sources.list 7 | owner: root 8 | group: root 9 | mode: 0644 10 | when: apt_reset_source_list 11 | 12 | - name: APT | Update the apt cache 13 | apt: 14 | update_cache: yes 15 | cache_valid_time: "{{apt_cache_valid_time}}" 16 | 17 | - name: APT | Remove packages that are no longer needed for dependencies 18 | apt: 19 | autoremove: "yes" 20 | when: apt_autoremove 21 | 22 | - name: APT | Remove .deb files for packages no longer on your system 23 | apt: 24 | autoclean: "yes" 25 | when: apt_autoclean 26 | 27 | - name: APT | Check for cached .deb files 28 | shell: "ls /var/cache/apt/archives/*.deb 2&> /dev/null | wc -l" 29 | register: apt_cache_check 30 | changed_when: no 31 | when: apt_clean 32 | 33 | - name: APT | Remove all cached .deb files 34 | shell: apt-get -y clean 35 | changed_when: apt_cache_check.stdout != "0" 36 | when: apt_clean and apt_cache_check.stdout != "0" 37 | 38 | - name: APT | Update the general configuration (/etc/apt/apt.conf.d/10general) 39 | template: 40 | src: etc_apt_apt.conf.d_10general.j2 41 | dest: /etc/apt/apt.conf.d/10general 42 | owner: root 43 | group: root 44 | mode: 0644 45 | 46 | - name: APT | Make sure the required packages are installed 20.04 and above 47 | set_fact: 48 | apt_packages_list: "{{ apt_default_packages | union (apt_default_packages_post20) | unique }}" 49 | when: ansible_facts['distribution_version'] is version('20.04', '>=') 50 | 51 | - name: APT | Make sure the required packages are installed 19.10 and below 52 | set_fact: 53 | apt_packages_list: "{{ apt_default_packages | union (apt_default_packages_pre20) | unique }}" 54 | when: ansible_facts['distribution_version'] is version('20.04', '<') 55 | 56 | - name: APT | Install Packages 57 | apt: 58 | pkg: "{{apt_packages_list}}" 59 | state: present 60 | -------------------------------------------------------------------------------- /templates/etc_apt_apt.conf.d_10general.j2: -------------------------------------------------------------------------------- 1 | // {{ ansible_managed }} 2 | 3 | // Do not install recommended or suggested Packages. 4 | APT::Install-Recommends "{{apt_install_recommends}}"; 5 | APT::Install-Suggests "{{apt_install_suggests}}"; 6 | 7 | APT::Get::Show-Upgraded "True"; 8 | 9 | // Allow apt-get autoremove to remove recommended or suggested Packages. 10 | APT::AutoRemove::RecommendsImportant "{{apt_autoremove_recommends}}"; 11 | APT::AutoRemove::SuggestsImportant "{{apt_autoremove_suggests}}"; 12 | 13 | // vim: ft=aptconf 14 | -------------------------------------------------------------------------------- /templates/etc_apt_sources.list.j2: -------------------------------------------------------------------------------- 1 | # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to 2 | # newer versions of the distribution. 3 | deb {{ apt_mirror_url }}/ubuntu/ {{ apt_release }} main restricted 4 | deb-src {{ apt_mirror_url }}/ubuntu/ {{ apt_release }} main restricted 5 | 6 | ## Major bug fix updates produced after the final release of the 7 | ## distribution. 8 | deb {{ apt_mirror_url }}/ubuntu/ {{ apt_release }}-updates main restricted 9 | deb-src {{ apt_mirror_url }}/ubuntu/ {{ apt_release }}-updates main restricted 10 | 11 | ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 12 | ## team. Also, please note that software in universe WILL NOT receive any 13 | ## review or updates from the Ubuntu security team. 14 | deb {{ apt_mirror_url }}/ubuntu/ {{ apt_release }} universe 15 | deb-src {{ apt_mirror_url }}/ubuntu/ {{ apt_release }} universe 16 | deb {{ apt_mirror_url }}/ubuntu/ {{ apt_release }}-updates universe 17 | deb-src {{ apt_mirror_url }}/ubuntu/ {{ apt_release }}-updates universe 18 | 19 | ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 20 | ## team, and may not be under a free licence. Please satisfy yourself as to 21 | ## your rights to use the software. Also, please note that software in 22 | ## multiverse WILL NOT receive any review or updates from the Ubuntu 23 | ## security team. 24 | 25 | deb {{ apt_mirror_url }}/ubuntu/ {{ apt_release }} multiverse 26 | deb-src {{ apt_mirror_url }}/ubuntu/ {{ apt_release }} multiverse 27 | deb {{ apt_mirror_url }}/ubuntu/ {{ apt_release }}-updates multiverse 28 | deb-src {{ apt_mirror_url }}/ubuntu/ {{ apt_release }}-updates multiverse 29 | 30 | ## N.B. software from this repository may not have been tested as 31 | ## extensively as that contained in the main release, although it includes 32 | ## newer versions of some applications which may provide useful features. 33 | ## Also, please note that software in backports WILL NOT receive any review 34 | ## or updates from the Ubuntu security team. 35 | deb {{ apt_mirror_url }}/ubuntu/ {{ apt_release }}-backports main restricted universe multiverse 36 | deb-src {{ apt_mirror_url }}/ubuntu/ {{ apt_release }}-backports main restricted universe multiverse 37 | 38 | deb http://security.ubuntu.com/ubuntu {{ apt_release }}-security main restricted 39 | deb-src http://security.ubuntu.com/ubuntu {{ apt_release }}-security main restricted 40 | deb http://security.ubuntu.com/ubuntu {{ apt_release }}-security universe 41 | deb-src http://security.ubuntu.com/ubuntu {{ apt_release }}-security universe 42 | deb http://security.ubuntu.com/ubuntu {{ apt_release }}-security multiverse 43 | deb-src http://security.ubuntu.com/ubuntu {{ apt_release }}-security multiverse 44 | 45 | ## Uncomment the following two lines to add software from Canonical's 46 | ## 'partner' repository. 47 | ## This software is not part of Ubuntu, but is offered by Canonical and the 48 | ## respective vendors as a service to Ubuntu users. 49 | # deb http://archive.canonical.com/ubuntu {{ apt_release }} partner 50 | # deb-src http://archive.canonical.com/ubuntu {{ apt_release }} partner 51 | 52 | ## Uncomment the following two lines to add software from Ubuntu's 53 | ## 'extras' repository. 54 | ## This software is not part of Ubuntu, but is offered by third-party 55 | ## developers who want to ship their latest software. 56 | # deb http://extras.ubuntu.com/ubuntu {{ apt_release }} main 57 | # deb-src http://extras.ubuntu.com/ubuntu {{ apt_release }} main 58 | -------------------------------------------------------------------------------- /test.yml: -------------------------------------------------------------------------------- 1 | - hosts: all 2 | vars_files: 3 | - 'defaults/main.yml' 4 | tasks: 5 | - include: 'tasks/main.yml' 6 | -------------------------------------------------------------------------------- /vagrant-inventory: -------------------------------------------------------------------------------- 1 | [anxs] 2 | anxs.local ansible_ssh_host=192.168.88.29 ansible_ssh_port=22 3 | -------------------------------------------------------------------------------- /version: -------------------------------------------------------------------------------- 1 | v2.1.0 2 | --------------------------------------------------------------------------------