Created
August 11, 2015 23:35
-
-
Save corny/1563378d459d74f8a696 to your computer and use it in GitHub Desktop.
Ansible playbook that uses apt to upgrade packages and remove/purge unneeded packages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: all | |
environment: | |
LC_ALL: C | |
LANG: C | |
tasks: | |
- name: Update APT package cache | |
apt: update_cache=yes cache_valid_time=600 | |
- name: Upgrade APT to the latest packages | |
apt: upgrade=dist | |
register: apt_result | |
- name: Autoremove unused packages | |
command: apt-get -y autoremove | |
register: apt_result | |
changed_when: "'packages will be REMOVED' in apt_result.stdout" | |
- name: Purge residual kernel packages | |
shell: apt-get remove -y --purge $(dpkg -l | grep "^rc\s*linux-image-" | awk '{print $2}' | tr '\n' ' ') | |
register: apt_result | |
changed_when: "'packages will be REMOVED' in apt_result.stdout" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if you are using non root account and want to do privilege escalation to root then you need to add
become: yes
become_user: root
to the apt-upgrade.yml file and when you execute script ad -K to the command: _ansible-playbook apt-upgrade.yml -K _ it will ask password then.
Another option is directly ssh as root or save root password to the protected place. Then also all hosts need to have same passwords