local/roles/obsidian/tasks/Linux.yaml

74 lines
1.9 KiB
YAML

---
- name: stat symlink
stat:
path: '{{ansible_env.HOME}}/.local/bin/Obsidian'
register: symlink_file
- name: get latest release
uri:
url: https://api.github.com/repos/obsidianmd/obsidian-releases/releases/latest
register: latest
- set_fact:
appimage: 'Obsidian-{{latest.json.name}}.AppImage'
- set_fact:
filepath: '{{ansible_env.HOME}}/.local/bin/{{appimage}}'
iconpath: 'share/icons/hicolor/512x512/apps/obsidian.png'
asset_query: '[?contains(name, `{{appimage}}`)] | [0]'
- set_fact:
needs_installed:
'{{not symlink_file.stat.exists or symlink_file.stat.lnk_source != filepath}}'
asset: '{{latest.json.assets | to_json | from_json | json_query(asset_query)}}'
- name: download latest version
get_url:
url: '{{asset.browser_download_url}}'
dest: '{{filepath}}'
mode: '0755'
- name: create directories
file:
path: '{{item}}'
state: directory
with_items:
- '{{ansible_env.HOME}}/.local/bin'
- '{{ansible_env.HOME}}/.local/share/icon/hicolor/512x512/apps'
- name: create symlink
file:
src: '{{filepath}}'
dest: '{{ansible_env.HOME}}/.local/bin/Obsidian'
state: link
- name: extract squashfs-root for app icon
when: needs_installed
command:
cmd: '{{ansible_env.HOME}}/.local/bin/Obsidian --appimage-extract'
chdir: '/tmp'
- name: copy icon file
when: needs_installed
copy:
src: '/tmp/squashfs-root/usr/{{iconpath}}'
dest: '{{ansible_env.HOME}}/.local/{{iconpath}}'
- name: remove squashfs-root directory
when: needs_installed
file:
path: '/tmp/squashfs-root'
state: absent
- name: create desktop file
template:
src: obsidian.desktop.j2
dest: '{{ansible_env.HOME}}/.local/share/applications/obsidian-obsidian.desktop'
notify: install desktop menu
- name: remove old appimage
when: needs_installed and symlink_file.stat.exists
file:
path: '{{symlink_file.stat.lnk_source}}'
state: absent
- include_tasks: Unix.yaml