-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(os_agent_auto_update): Configure automatic updating for OS Agent
Fixes #25
- Loading branch information
1 parent
6fb5eab
commit ce1a7e8
Showing
10 changed files
with
174 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
os_agent_auto_update | ||
========= | ||
|
||
Schedule ansible-playbook to check for and install OS Agent updates with cron | ||
|
||
Requirements | ||
------------ | ||
|
||
- Ansible must be installed on the remote host to run the auto update playbook from cron. The role will complete successfully without Ansible being installed, but the cron job will not run successfully. By default, the role will automatically do a user install of ansible with pip. | ||
- A playbook is copied to the remote host that is scheduled in cron to check for and install OS Agent updates. This playbook has a task with `become: true`, so the user runs the schedule should have passwordless sudo configured to run non-interactively. | ||
|
||
Role Variables | ||
-------------- | ||
|
||
The following varaibles are defined in `defaults/main.yml` | ||
|
||
```yaml | ||
# The path that the automatic update playbook will be copied to for scheduling | ||
os_agent_auto_update_playbook_dir: /home/homeassistant/playbooks | ||
|
||
# Install ansible on the remote host so that the update playbook can run in cron. Set to false to you already have ansible installed, or need a specific Ansible version. | ||
os_agent_auto_update_install_ansible: true | ||
``` | ||
Dependencies | ||
------------ | ||
none | ||
Example Playbook | ||
---------------- | ||
```yaml | ||
- hosts: pi | ||
roles: | ||
- name: jhampson_dbre.home_assistant.os_agent_auto_update | ||
``` | ||
License | ||
------- | ||
MIT | ||
Author Information | ||
------------------ | ||
@jhampson-dbre |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
# defaults file for os_agent_auto_update | ||
os_agent_auto_update_playbook_dir: /home/homeassistant/playbooks | ||
os_agent_auto_update_install_ansible: true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
- hosts: localhost | ||
connection: local | ||
vars: | ||
update_os_agent_arch: | ||
"i386": "i386" | ||
"i686": "none" | ||
"x86_64": "x86_64" | ||
"arm": "armv5" | ||
"armv6l": "none" | ||
"armv7l": "armv7" | ||
"aarch64": "aarch64" | ||
|
||
tasks: | ||
- name: Get download url for latest os-agent .deb release | ||
shell: | | ||
curl -s https://api.github.com/repos/home-assistant/os-agent/releases/latest \ | ||
| grep "browser_download_url.*{{ update_os_agent_arch[ansible_architecture] }}.deb" \ | ||
| cut -d : -f 2,3 \ | ||
| tr -d \" | ||
register: os_agent_latest_url | ||
failed_when: os_agent_latest_url.stdout is not search('os-agent_.*_linux_.*.deb') | ||
changed_when: false | ||
check_mode: no | ||
args: | ||
warn: false | ||
|
||
- name: Install os-agent | ||
apt: | ||
deb: "{{ os_agent_latest_url.stdout|trim }}" | ||
become: true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
galaxy_info: | ||
author: Jared Hampson | ||
description: Automatic update for Home Assistant OS Agent | ||
|
||
# If the issue tracker for your role is not on github, uncomment the | ||
# next line and provide a value | ||
# issue_tracker_url: http://example.com/issue/tracker | ||
|
||
# Choose a valid license ID from https://spdx.org - some suggested licenses: | ||
license: MIT | ||
|
||
min_ansible_version: 2.9 | ||
|
||
# If this a Container Enabled role, provide the minimum Ansible Container version. | ||
# min_ansible_container_version: | ||
|
||
# | ||
# Provide a list of supported platforms, and for each platform a list of versions. | ||
# If you don't wish to enumerate all versions for a particular platform, use 'all'. | ||
# To view available platforms and versions (or releases), visit: | ||
# https://galaxy.ansible.com/api/v1/platforms/ | ||
# | ||
platforms: | ||
- name: Debian | ||
versions: | ||
- buster | ||
|
||
galaxy_tags: | ||
- home | ||
- assistant | ||
- supervised | ||
- raspberry | ||
- pi | ||
- hassio | ||
- hacs | ||
|
||
dependencies: [] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
# tasks file for os_agent_auto_update | ||
- name: create directory for auto update playbook | ||
file: | ||
path: "{{ os_agent_auto_update_playbook_dir }}" | ||
state: directory | ||
mode: 0700 | ||
|
||
- name: copy OS Agent update playbook | ||
copy: | ||
src: update_os_agent.yml | ||
dest: "{{ os_agent_auto_update_playbook_dir }}/update_os_agent.yml" | ||
mode: 0700 | ||
|
||
- name: ensure ansible is installed | ||
pip: | ||
name: ansible<=2.10 | ||
extra_args: --user | ||
executable: pip3 | ||
when: os_agent_auto_update_install_ansible|bool | ||
|
||
- name: schedule periodic update of OS Agent | ||
cron: | ||
name: "update OS Agent" | ||
minute: "0" | ||
hour: "5" | ||
job: "ansible-playbook {{ os_agent_auto_update_playbook_dir }}/update_os_agent.yml" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
localhost |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
- hosts: localhost | ||
roles: | ||
- name: os_agent_auto_update |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
# vars file for os_agent_auto_update | ||
os_agent_auto_update_arch: | ||
"i386": | ||
os_agent: "i386" | ||
"i686": | ||
os_agent: "none" | ||
"x86_64": | ||
os_agent: "x86_64" | ||
"arm": | ||
os_agent: "armv5" | ||
"armv6l": | ||
os_agent: "none" | ||
"armv7l": | ||
os_agent: "armv7" | ||
"aarch64": | ||
os_agent: "aarch64" |
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