commit 1fe4c617dbe68bdef09cdfd2c38a8fa0fa968a71 Author: Marty Oehme Date: Sat Jul 24 11:51:09 2021 +0200 Add system upgrade role initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fafc0aa --- /dev/null +++ b/.gitignore @@ -0,0 +1,53 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/vim,linux,vagrant,ansible +# Edit at https://www.toptal.com/developers/gitignore?templates=vim,linux,vagrant,ansible + +### Ansible ### +*.retry + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### Vagrant ### +# General +.vagrant/ + +# Log files (if you are creating logs in debug mode, uncomment this) +# *.log + +### Vagrant Patch ### +*.box + +### Vim ### +# Swap +[._]*.s[a-v][a-z] +!*.svg # comment out if you don't need vector files +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ + +# End of https://www.toptal.com/developers/gitignore/api/vim,linux,vagrant,ansible diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..a15c349 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,11 @@ +Vagrant.configure('2') do |config| + config.vm.define 'tau' do |debian| + debian.vm.box = 'bento/ubuntu-20.04' + debian.vm.network :private_network, ip: '192.168.27.2' + debian.vm.hostname = 'testing' + debian.vm.provider 'virtualbox' do |vb| + vb.memory = '2048' + vb.cpus = 2 + end + end +end diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..aff6d05 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,4 @@ +[defaults] + +inventory = ./inventory +group = testing diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..b34d713 --- /dev/null +++ b/playbook.yml @@ -0,0 +1,10 @@ +--- +- hosts: all + tasks: + - name: Test connection + ansible.builtin.ping: + +- hosts: all + roles: + - system-upgrade + - docker diff --git a/roles/system-upgrade/handlers/main.yml b/roles/system-upgrade/handlers/main.yml new file mode 100644 index 0000000..e51fb2e --- /dev/null +++ b/roles/system-upgrade/handlers/main.yml @@ -0,0 +1,10 @@ +- name: reboot host + reboot: + msg: "Reboot initiated by Ansible" + connect_timeout: 5 + reboot_timeout: 600 + pre_reboot_delay: 0 + post_reboot_delay: 30 + test_command: whoami + become: true + when: reboot_required_file.stat.exists diff --git a/roles/system-upgrade/tasks/Ubuntu.yml b/roles/system-upgrade/tasks/Ubuntu.yml new file mode 100644 index 0000000..983e6b5 --- /dev/null +++ b/roles/system-upgrade/tasks/Ubuntu.yml @@ -0,0 +1,38 @@ +- name: Ensure aptitude installed + apt: + name: "aptitude" + state: present + tags: + - apt + - download + - packages + become: true + +- name: Ensure OS upgraded + apt: + upgrade: dist + tags: + - apt + - update + - os + become: true + +- name: Check if reboot is necessary + register: reboot_required_file + stat: + path: /var/run/reboot-required + get_md5: no + tags: + - os + - reboot + notify: reboot host + +- name: Ensure all packages updated + apt: + name: "*" + state: latest # noqa 403 + tags: + - apt + - update + - packages + become: true diff --git a/roles/system-upgrade/tasks/main.yml b/roles/system-upgrade/tasks/main.yml new file mode 100644 index 0000000..9d0c2a3 --- /dev/null +++ b/roles/system-upgrade/tasks/main.yml @@ -0,0 +1,11 @@ +--- +# Bring the bare-metal system to the newest updated status + +- name: "Select tasks for {{ ansible_distribution }} {{ ansible_distribution_major_version }}" + include_tasks: "{{ distribution }}" + with_first_found: + - "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml" + - "{{ ansible_distribution }}.yml" + - "{{ ansible_os_family }}.yml" + loop_control: + loop_var: distribution