Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unattend upgrades [WIP] #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ansible/group_vars/all/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ wifi_networks:

- ssid: "Woestgaafsecure Gamehall"
password: "fantazero"

unattended_upgrades:
security: true
all: true
4 changes: 4 additions & 0 deletions ansible/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
service:
name: "sshd"
state: "reloaded"

- name: "systemctl daemon-reload"
systemd:
daemon_reload: true
3 changes: 3 additions & 0 deletions ansible/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@

- name: "install graphical environment"
include_tasks: "tasks/graphical.yml"

- name: "configure unattended upgrades"
include_tasks: "tasks/security.yml"
4 changes: 2 additions & 2 deletions ansible/scripts/authorize-github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fi
# Note that bash cannot return strings, and instead redirects the stdout of
# commands called in the function to the caller.
function get_without_otp() {
username = $1
username=$1
curl \
-u $username \
--data '{"scopes":["read:org"],"note":"hapPI token"}' \
Expand All @@ -44,7 +44,7 @@ read OTPCODE

if [ -n $OTPCODE ]; then
echo "Requesting token with OTP code."
HTTPRESULT=$(get_with_otp $USERNAME $OTPCODE)
HTTPRESULT=$(get_without_otp $USERNAME $OTPCODE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a temporary fix to make it work on OSX, I'll revert this line.

else
echo "Requesting token without OTP code."
HTTPRESULT=$(get_without_otp $USERNAME)
Expand Down
2 changes: 1 addition & 1 deletion ansible/scripts/get-authorized-keys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ for team in ${TEAMS[@]}; do
done

echo "Updating authorized-keys template."
mv --backup=numbered .new-authorized-keys templates/home/pi/.ssh/authorized_keys.j2
mv .new-authorized-keys templates/home/pi/.ssh/authorized_keys.j2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same


echo "Done!"
38 changes: 38 additions & 0 deletions ansible/tasks/security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
# Needed because of Ansible issue #25414
- name: "check if unattended-upgrades is not in progress"
shell:
"while fuser /var/lib/dpkg/lock; do sleep 1; done;"
become: true
changed_when: false

- name: "install common utilities"
apt:
name:
- "aptitude"
- "htop"
- "unattended-upgrades"
- "haveged"
state: "present"

# uncomment in case of merge list error
# https://www.ihaveapc.com/2011/05/how-to-fix-problem-with-mergelist-varlibaptlists-error-in-ubuntu-11-04/
#- name: "remove merge list"
# command: "rm /var/lib/apt/lists/* -vf"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be expanded to a file: task I think, but we shouldn't need this anyway.


- name: "update all packages"
apt:
upgrade: "yes"
update_cache: true
cache_valid_time: 100

- name: "configure unattended-upgrades"
template:
src: "templates/{{ item }}.j2"
dest: "/{{ item }}"
with_items:
- "etc/apt/apt.conf.d/50unattended-upgrades"
notify:
- "systemctl daemon-reload"


29 changes: 29 additions & 0 deletions ansible/templates/etc/apt/apt.cond.d/50unattended-upgrades.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// {{ ansible_managed }}

Unattended-Upgrade::Allowed-Origins {
{% if unattended_upgrades.security %}
"${distro_id} ${distro_codename}-security";
{% endif %}
{% if unattended_upgrades.all %}

"${distro_id} stable";
"${distro_id} ${distro_codename}-updates";
"LP-PPA-certbot-certbot:${distro_codename}";
"yarn:stable";
{% endif %}
};

Unattended-Upgrade::Package-Blacklist { };

// Do automatic removal of new unused dependencies after the upgrade
// (equivalent to apt-get autoremove)
Unattended-Upgrade::Remove-Unused-Dependencies "true";

// Automatically reboot *WITHOUT CONFIRMATION*
// if the file /var/run/reboot-required is found after the upgrade
Unattended-Upgrade::Automatic-Reboot "true";

// If automatic reboot is enabled and needed, reboot at the specific
// time instead of immediately
// Default: "now"
Unattended-Upgrade::Automatic-Reboot-Time "04:30";