Update to 2022-02-18 16:00

This commit is contained in:
Daniel Berteaud
2022-02-18 16:00:06 +01:00
parent 67e32c9d59
commit 767adc1e83
19 changed files with 282 additions and 2 deletions

View File

@@ -0,0 +1,10 @@
---
- name: Compress previous version
command: tar cf {{ pgweb_root_dir }}/archives/{{ pgweb_current_version }}.tar.zst --use-compress-program=zstd ./
args:
chdir: "{{ pgweb_root_dir }}/archives/{{ pgweb_current_version }}"
warn: False
environment:
ZSTD_CLEVEL: 10
tags: pgweb

View File

@@ -0,0 +1,10 @@
---
- name: Create archive directory
file: path={{ pgweb_root_dir }}/archives/{{ pgweb_current_version }} state=directory mode=700
tags: pgweb,pg
- name: Archive previous version
copy: src={{ pgweb_root_dir }}/bin/pgweb dest={{ pgweb_root_dir }}/archives/{{ pgweb_current_version }} remote_src=True
tags: pgweb,pg

View File

@@ -0,0 +1,13 @@
---
- name: Remove tmp and obsolete files
file: path={{ item }} state=absent
loop:
- "{{ pgweb_root_dir }}/tmp/pgweb_linux_amd64"
- "{{ pgweb_root_dir }}/tmp/pgweb_linux_amd64.zip"
tags: pgweb,pg
- name: Remove temp previous version dir
file: path={{ pgweb_root_dir }}/archives/{{ pgweb_current_version }} state=absent
when: pgweb_install_mode == 'upgrade'
tags: pgweb,pg

View File

@@ -0,0 +1,20 @@
---
- name: List existing bookmarks
shell: ls -1 {{ pgweb_root_dir }}/bookmarks/ | perl -pe 's/\.toml$//'
register: pgweb_current_bookmarks
changed_when: False
tags: pgweb,pg
- name: Remove unmanaged bookmarks
file: path={{ pgweb_root_dir }}/bookmarks/{{ item }}.toml state=absent
loop: "{{ pgweb_current_bookmarks.stdout_lines }}"
when: not item in pgweb_bookmarks | map(attribute='name') | list
notify: restart pgweb
tags: pgweb,pg
- name: Configure bookmarks
template: src=bookmark.toml.j2 dest={{ pgweb_root_dir }}/bookmarks/{{ item.name }}.toml owner=root group={{ pgweb_user }} mode=640
loop: "{{ pgweb_bookmarks }}"
notify: restart pgweb
tags: pgweb,pg

View File

@@ -0,0 +1,25 @@
---
- name: Create directories
file: path={{ item.dir }} state=directory owner={{ item.owner | default(omit) }} group={{ item.group | default(omit) }} mode={{ item.mode | default(omit) }}
loop:
- dir: "{{ pgweb_root_dir }}"
- dir: "{{ pgweb_root_dir }}/bin"
- dir: "{{ pgweb_root_dir }}/bookmarks"
- dir: "{{ pgweb_root_dir }}/archives"
owner: root
group: root
mode: 700
- dir: "{{ pgweb_root_dir }}/backup"
owner: root
group: root
mode: 700
- dir: "{{ pgweb_root_dir }}/meta"
owner: root
group: root
mode: 700
- dir: "{{ pgweb_root_dir }}/tmp"
owner: "{{ pgweb_user }}"
group: "{{ pgweb_user }}"
mode: 700
tags: pgweb,pg

View File

@@ -0,0 +1,20 @@
---
- include_vars: "{{ item }}"
with_first_found:
- "{{ role_path }}/vars/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
- "{{ role_path }}/vars/{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
- "{{ role_path }}/vars/{{ ansible_distribution }}.yml"
- "{{ role_path }}/vars/{{ ansible_os_family }}.yml"
tags: pgweb,pg
# Detect installed version (if any) and detect if it's an install / upgrade / nothing
- block:
- import_tasks: ../includes/webapps_set_install_mode.yml
vars:
- root_dir: "{{ pgweb_root_dir }}"
- version: "{{ pgweb_version }}"
- set_fact: pgweb_install_mode={{ (install_mode == 'upgrade' and not pgweb_manage_upgrade) | ternary('none',install_mode) }}
- set_fact: pgweb_current_version={{ current_version | default('') }}
tags: pgweb,pg

View File

@@ -0,0 +1,40 @@
---
- name: Install dependencies
package: name={{ pgweb_packages }}
tags: pgweb,pg
- when: pgweb_install_mode != 'none'
block:
- name: Download pgweb
get_url:
url: "{{ pgweb_archive_url }}"
dest: "{{ pgweb_root_dir }}/tmp/"
checksum: sha256:{{ pgweb_archive_sha256 }}
- name: Extract archive
unarchive:
src: "{{ pgweb_root_dir }}/tmp/pgweb_linux_amd64.zip"
dest: "{{ pgweb_root_dir }}/tmp/"
remote_src: True
- name: Install pgweb binary
copy:
src: "{{ pgweb_root_dir }}/tmp/pgweb_linux_amd64"
dest: "{{ pgweb_root_dir }}/bin/pgweb"
remote_src: True
mode: 755
notify: restart pgweb
tags: pgweb,pg
- name: Install systemd unit
template: src=pgweb.service.j2 dest=/etc/systemd/system/pgweb.service
register: pgweb_unit
notify: restart pgweb
tags: pgweb,pg
- name: Reload systemd
systemd: daemon_reload=True
when: pgweb_unit.changed
tags: pgweb,pg

View File

@@ -0,0 +1,8 @@
---
- name: Handle pgweb ports in the firewall
iptables_raw:
name: pgweb_port
state: "{{ (pgweb_src_ip | length > 0) | ternary('present','absent') }}"
rules: "-A INPUT -m state --state NEW -p tcp --dport {{ pgweb_port }} -s {{ pgweb_src_ip | join(',') }} -j ACCEPT"
tags: firewall,pgweb,pg

View File

@@ -0,0 +1,17 @@
---
- include: user.yml
- include: directories.yml
- include: facts.yml
- include: archive_pre.yml
when: pgweb_install_mode == 'upgrade'
- include: install.yml
- include: conf.yml
- include: iptables.yml
when: iptables_manage | default(True)
- include: services.yml
- include: archive_post.yml
when: pgweb_install_mode == 'upgrade'
- include: write_version.yml
- include: cleanup.yml

View File

@@ -0,0 +1,5 @@
---
- name: Start and enable service
service: name=pgweb state=started enabled=True
tags: pgweb,pg

View File

@@ -0,0 +1,9 @@
---
- name: Create user account
user:
name: "{{ pgweb_user }}"
system: True
home: "{{ pgweb_root_dir }}"
shell: /sbin/nologin
tags: pgweb,pg

View File

@@ -0,0 +1,5 @@
---
- name: Write installed version
copy: content={{ pgweb_version }} dest={{ pgweb_root_dir }}/meta/ansible_version
tags: pgweb,pg