From 297501d35e05eefcc0bc596d2144cc1870de1024 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Tue, 18 May 2021 23:05:30 +0300 Subject: [PATCH] OpenWRT WAP daily updates script. Download package updates and notify if there are pending updates. --- roles/wap/tasks/main.yaml | 24 ++++++++++++++++++++++++ roles/wap/templates/daily.j2 | 7 +++++++ 2 files changed, 31 insertions(+) create mode 100644 roles/wap/templates/daily.j2 diff --git a/roles/wap/tasks/main.yaml b/roles/wap/tasks/main.yaml index 6ea54f2..5125fd4 100644 --- a/roles/wap/tasks/main.yaml +++ b/roles/wap/tasks/main.yaml @@ -5,6 +5,30 @@ - ansible_distribution == "OpenWrt" - ansible_distribution_major_version == "19" +- name: Install packages + loop: + - curl + community.general.opkg: + name: '{{ item }}' + state: present + update_cache: true + +- name: Copy the daily updates script + ansible.builtin.template: + dest: &daily /usr/sbin/daily + group: root + mode: 0o0755 + owner: root + src: daily.j2 + +- name: Set the daily updates script Cron job + ansible.builtin.cron: + hour: "3" + job: *daily + minute: "1" + name: Daily updates + state: present + - name: Create the www directory ansible.builtin.file: path: /var/www diff --git a/roles/wap/templates/daily.j2 b/roles/wap/templates/daily.j2 new file mode 100644 index 0000000..a0e3cfb --- /dev/null +++ b/roles/wap/templates/daily.j2 @@ -0,0 +1,7 @@ +#!/bin/sh +set -eu + +opkg update +opkg list-upgradable | awk '{print $1}' | sort | xargs -rn1 opkg upgrade --download-only + +[ -z "$(opkg list-upgradable)" ] || curl https://notify.shore.co.il/send?message={{ (ansible_facts["hostname"] + " has pending updates.") | urlencode }} -- GitLab