update-system/tasks/update-Debian.yml

70 lines
1.7 KiB
YAML

---
- name: Update apt keys
become: true
command: apt-key update
when: ansible_os_family == "Debian" or ansible_os_family == "OSMC"
- name: Upgrade all packages to the latest version
become: true
apt:
upgrade: dist
update_cache: true
cache_valid_time: 3600
environment:
PATH: "{{ ansible_env.PATH }}:/sbin:/usr/sbin"
when: ansible_os_family == "Debian" or ansible_os_family == "OSMC"
- name: Remove useless packages from the cache
become: true
become_method: sudo
ignore_errors: true
command: >
apt-get autoremove -y
environment:
PATH: "{{ ansible_env.PATH }}:/sbin:/usr/sbin"
when: ansible_os_family == "Debian" or ansible_os_family == "OSMC"
- name: install packages
become: true
apt:
name: "{{ package_list | list }}"
state: present
when: install and ansible_os_family == "Debian"
- name: Check if a reboot is required
register: reboot_required_file
stat:
path: /var/run/reboot-required get_md5=no
- name: Needs Reboot
debug:
msg: "Restart Required!!"
ignore_errors: true
when: reboot_required_file.stat.exists == true
- name: "Reboot"
shell: 'sleep 2 && shutdown -r now'
become: true
async: 1
poll: 0
ignore_errors: true
when: reboot_required_file.stat.exists == true
# This pause is mandatory, otherwise the existing control connection gets reused!
- name: "pause "
pause:
seconds: 30
when: reboot_required_file.stat.exists == true
- name: "wait till server comes back online"
local_action: shell ansible -u {{ ansible_user_id }} -m ping {{ inventory_hostname }}
register: result
until: result.rc == 0
retries: 30
delay: 15
when: reboot_required_file.stat.exists == true
- name: Re-gather facts
action: setup