forked from jakub/ansible
Compare commits
20 Commits
595c0624d6
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| f4262bcb27 | |||
| 5c69d3a03f | |||
| 547c9fadc5 | |||
| c07181291c | |||
| 1a0ce36efe | |||
| 8b57f27ec6 | |||
| 085e7177f4 | |||
| 3099a0b2b8 | |||
| 3d89bc523e | |||
| 61d288f92a | |||
| 61beedd023 | |||
| bb37cdaa53 | |||
| b805b506b4 | |||
| 9fad4e4d1a | |||
| a632da2a62 | |||
| cf21ad70c1 | |||
| 1deb268d73 | |||
| 8373252ae9 | |||
| 13a48cd734 | |||
| b497723769 |
@@ -1,29 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Upload and run stack health checks
|
|
||||||
hosts: proxmox
|
|
||||||
become: true
|
|
||||||
|
|
||||||
vars:
|
|
||||||
health_script_path: /data/compose/nextcloud/stack-health.sh
|
|
||||||
|
|
||||||
tasks:
|
|
||||||
- name: Upload stack-health.sh
|
|
||||||
ansible.builtin.copy:
|
|
||||||
src: files/stack-health.sh
|
|
||||||
dest: "{{ health_script_path }}"
|
|
||||||
mode: '0755'
|
|
||||||
|
|
||||||
- name: Run stack-health.sh
|
|
||||||
ansible.builtin.shell: "{{ health_script_path }}"
|
|
||||||
register: health
|
|
||||||
args:
|
|
||||||
executable: /bin/bash
|
|
||||||
|
|
||||||
- name: Show health output
|
|
||||||
ansible.builtin.debug:
|
|
||||||
msg: "{{ health.stdout | default('no stdout') }}"
|
|
||||||
|
|
||||||
- name: Fail if checks failed (rc != 0)
|
|
||||||
ansible.builtin.fail:
|
|
||||||
msg: "Health checks failed"
|
|
||||||
when: health.rc != 0
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Update Collabora (pull + recreate in same compose project)
|
|
||||||
hosts: proxmox
|
|
||||||
become: true
|
|
||||||
|
|
||||||
vars:
|
|
||||||
collabora_compose_path: /data/compose/nextcloud/collabora-only.yml
|
|
||||||
collabora_project_name: nextcloud-collabora # based on your labels
|
|
||||||
|
|
||||||
tasks:
|
|
||||||
- name: Pull collabora/code:latest image
|
|
||||||
community.docker.docker_image:
|
|
||||||
name: collabora/code
|
|
||||||
tag: latest
|
|
||||||
source: pull
|
|
||||||
|
|
||||||
# Compose file contains only service "collabora", so this acts on that service only
|
|
||||||
- name: Compose pull (ensure freshest image)
|
|
||||||
community.docker.docker_compose_v2:
|
|
||||||
project_name: "{{ collabora_project_name }}"
|
|
||||||
files: ["{{ collabora_compose_path }}"]
|
|
||||||
pull: always
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: Recreate collabora with new image
|
|
||||||
community.docker.docker_compose_v2:
|
|
||||||
project_name: "{{ collabora_project_name }}"
|
|
||||||
files: ["{{ collabora_compose_path }}"]
|
|
||||||
recreate: always
|
|
||||||
state: present
|
|
||||||
@@ -1,2 +1,8 @@
|
|||||||
[linux_servers]
|
[linux_servers]
|
||||||
proxmox ansible_host=192.168.69.2
|
jimbuntu ansible_host=192.168.19.4
|
||||||
|
jim_storage ansible_host=192.168.19.7
|
||||||
|
portainer2 ansible_host=192.168.52.9
|
||||||
|
portainernode ansible_host=192.168.52.21
|
||||||
|
|
||||||
|
[local]
|
||||||
|
localhost ansible_connection=local
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
[mikrotiks]
|
[mikrotiks]
|
||||||
main_mikrotik_fencl ansible_host=192.168.69.1
|
jim ansible_host=192.168.19.2
|
||||||
|
hellsos ansible_host=192.168.40.1
|
||||||
@@ -59,4 +59,4 @@
|
|||||||
- name: Remove backup file from router
|
- name: Remove backup file from router
|
||||||
shell: timeout 15 ssh -o StrictHostKeyChecking=no {{ ansible_user }}@{{ ansible_host }} -p {{ ansible_port }} "/file remove {{ router_name }}-{{ current_date }}-backup.backup"
|
shell: timeout 15 ssh -o StrictHostKeyChecking=no {{ ansible_user }}@{{ ansible_host }} -p {{ ansible_port }} "/file remove {{ router_name }}-{{ current_date }}-backup.backup"
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
when: system_identity.rc == 0
|
when: system_identity.rc == 0
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Nextcloud backup (config, custom_apps, DB)
|
|
||||||
hosts: proxmox
|
|
||||||
become: true
|
|
||||||
|
|
||||||
vars:
|
|
||||||
nc_root: /data/compose/nextcloud
|
|
||||||
backup_dir: "{{ nc_root }}/backup-{{ ansible_date_time.date }}"
|
|
||||||
db_container: nextcloud-db
|
|
||||||
|
|
||||||
tasks:
|
|
||||||
- name: Ensure backup directory exists
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "{{ backup_dir }}"
|
|
||||||
state: directory
|
|
||||||
mode: '0755'
|
|
||||||
|
|
||||||
# Use archive module to create tar.gz directly on the remote host
|
|
||||||
- name: Archive config directory
|
|
||||||
ansible.builtin.archive:
|
|
||||||
path: "{{ nc_root }}/config"
|
|
||||||
dest: "{{ backup_dir }}/config.tgz"
|
|
||||||
format: gz
|
|
||||||
|
|
||||||
- name: Archive custom_apps directory
|
|
||||||
ansible.builtin.archive:
|
|
||||||
path: "{{ nc_root }}/custom_apps"
|
|
||||||
dest: "{{ backup_dir }}/custom_apps.tgz"
|
|
||||||
format: gz
|
|
||||||
|
|
||||||
# Dump DB directly to a file on the host (avoid shuttling dump through Ansible)
|
|
||||||
- name: Dump MariaDB from container to file
|
|
||||||
ansible.builtin.shell: |
|
|
||||||
set -euo pipefail
|
|
||||||
docker exec {{ db_container }} sh -c 'command -v mariadb-dump >/dev/null && mariadb-dump -u"$$MYSQL_USER" -p"$$MYSQL_PASSWORD" "$$MYSQL_DATABASE" || mysqldump -u"$$MYSQL_USER" -p"$$MYSQL_PASSWORD" "$$MYSQL_DATABASE"' \
|
|
||||||
> "{{ backup_dir }}/db.sql"
|
|
||||||
args:
|
|
||||||
executable: /bin/bash
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Upgrade Nextcloud to 31-apache (pull + recreate + occ)
|
|
||||||
hosts: proxmox
|
|
||||||
become: true
|
|
||||||
|
|
||||||
vars:
|
|
||||||
nc_container: nextcloud
|
|
||||||
nc_image_tag: "31-apache" # change to 32-apache when you step to next major
|
|
||||||
# Ports/volumes/env exactly as you use:
|
|
||||||
nc_root: /data/compose/nextcloud
|
|
||||||
nc_http_port: "8080:80"
|
|
||||||
|
|
||||||
tasks:
|
|
||||||
- name: Gather nextcloud container info
|
|
||||||
community.docker.docker_container_info:
|
|
||||||
name: "{{ nc_container }}"
|
|
||||||
register: nc_info
|
|
||||||
|
|
||||||
- name: Derive compose project & network from existing container
|
|
||||||
ansible.builtin.set_fact:
|
|
||||||
nc_project: "{{ nc_info.container.Config.Labels['com.docker.compose.project'] | default('nextcloud') }}"
|
|
||||||
nc_networks: "{{ (nc_info.container.NetworkSettings.Networks | default({})).keys() | list }}"
|
|
||||||
nc_net_primary: "{{ (nc_info.container.NetworkSettings.Networks | default({})).keys() | list | first }}"
|
|
||||||
when: nc_info.exists
|
|
||||||
|
|
||||||
- name: Enable maintenance mode
|
|
||||||
community.docker.docker_container_exec:
|
|
||||||
container: "{{ nc_container }}"
|
|
||||||
user: "www-data"
|
|
||||||
command: php occ maintenance:mode --on
|
|
||||||
|
|
||||||
- name: Render one-off compose for nextcloud (single-service)
|
|
||||||
ansible.builtin.copy:
|
|
||||||
dest: /tmp/nc.yml
|
|
||||||
mode: '0644'
|
|
||||||
content: |
|
|
||||||
name: {{ nc_project }}
|
|
||||||
services:
|
|
||||||
nextcloud:
|
|
||||||
image: nextcloud:{{ nc_image_tag }}
|
|
||||||
container_name: {{ nc_container }}
|
|
||||||
restart: unless-stopped
|
|
||||||
networks: [cloud]
|
|
||||||
ports: ["{{ nc_http_port }}"]
|
|
||||||
volumes:
|
|
||||||
- {{ nc_root }}/config:/var/www/html/config
|
|
||||||
- {{ nc_root }}/data:/var/www/html/data
|
|
||||||
- {{ nc_root }}/custom_apps:/var/www/html/custom_apps
|
|
||||||
environment:
|
|
||||||
TZ: Europe/Prague
|
|
||||||
MYSQL_DATABASE: nextcloud
|
|
||||||
MYSQL_USER: nextcloud
|
|
||||||
MYSQL_PASSWORD: dbpassword
|
|
||||||
MYSQL_HOST: nextclouddb
|
|
||||||
REDIS_HOST: redis
|
|
||||||
NEXTCLOUD_ADMIN_USER: root
|
|
||||||
NEXTCLOUD_ADMIN_PASSWORD: '1234SilneHeslo.-.'
|
|
||||||
networks:
|
|
||||||
cloud:
|
|
||||||
external: true
|
|
||||||
name: {{ nc_net_primary }}
|
|
||||||
|
|
||||||
- name: Pull the new Nextcloud image
|
|
||||||
community.docker.docker_compose_v2:
|
|
||||||
project_name: "{{ nc_project }}"
|
|
||||||
files: ["/tmp/nc.yml"]
|
|
||||||
pull: always
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: Recreate Nextcloud with the new image
|
|
||||||
community.docker.docker_compose_v2:
|
|
||||||
project_name: "{{ nc_project }}"
|
|
||||||
files: ["/tmp/nc.yml"]
|
|
||||||
recreate: always
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: Run occ upgrade
|
|
||||||
community.docker.docker_container_exec:
|
|
||||||
container: "{{ nc_container }}"
|
|
||||||
user: "www-data"
|
|
||||||
command: php occ upgrade
|
|
||||||
|
|
||||||
- name: Recommended DB maintenance (safe to run)
|
|
||||||
community.docker.docker_container_exec:
|
|
||||||
container: "{{ nc_container }}"
|
|
||||||
user: "www-data"
|
|
||||||
command: php occ db:add-missing-indices
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: Convert filecache bigint (safe)
|
|
||||||
community.docker.docker_container_exec:
|
|
||||||
container: "{{ nc_container }}"
|
|
||||||
user: "www-data"
|
|
||||||
command: php occ db:convert-filecache-bigint --no-interaction
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: Disable maintenance mode
|
|
||||||
community.docker.docker_container_exec:
|
|
||||||
container: "{{ nc_container }}"
|
|
||||||
user: "www-data"
|
|
||||||
command: php occ maintenance:mode --off
|
|
||||||
|
|
||||||
- name: Show status
|
|
||||||
community.docker.docker_container_exec:
|
|
||||||
container: "{{ nc_container }}"
|
|
||||||
user: "www-data"
|
|
||||||
command: php occ status
|
|
||||||
register: nc_status
|
|
||||||
|
|
||||||
- name: Print status
|
|
||||||
ansible.builtin.debug:
|
|
||||||
msg: "{{ nc_status.stdout | default('no output') }}"
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Update Redis (pull + recreate, same stack)
|
|
||||||
hosts: proxmox
|
|
||||||
become: true
|
|
||||||
|
|
||||||
vars:
|
|
||||||
nc_container: nextcloud
|
|
||||||
redis_container: redis
|
|
||||||
redis_image: "redis:7-alpine"
|
|
||||||
nc_root: /data/compose/nextcloud
|
|
||||||
|
|
||||||
tasks:
|
|
||||||
- name: Gather nextcloud container info (to learn project + network)
|
|
||||||
community.docker.docker_container_info:
|
|
||||||
name: "{{ nc_container }}"
|
|
||||||
register: nc_info
|
|
||||||
|
|
||||||
- name: Derive compose project & network
|
|
||||||
ansible.builtin.set_fact:
|
|
||||||
nc_project: "{{ nc_info.container.Config.Labels['com.docker.compose.project'] | default('nextcloud') }}"
|
|
||||||
nc_net_primary: "{{ (nc_info.container.NetworkSettings.Networks | default({})).keys() | list | first }}"
|
|
||||||
when: nc_info.exists
|
|
||||||
|
|
||||||
- name: Enable maintenance mode (optional safety)
|
|
||||||
community.docker.docker_container_exec:
|
|
||||||
container: "{{ nc_container }}"
|
|
||||||
user: "www-data"
|
|
||||||
command: php occ maintenance:mode --on
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: Render one-off compose for Redis
|
|
||||||
ansible.builtin.copy:
|
|
||||||
dest: /tmp/redis.yml
|
|
||||||
mode: '0644'
|
|
||||||
content: |
|
|
||||||
name: {{ nc_project }}
|
|
||||||
services:
|
|
||||||
redis:
|
|
||||||
image: {{ redis_image }}
|
|
||||||
container_name: {{ redis_container }}
|
|
||||||
restart: unless-stopped
|
|
||||||
networks: [cloud]
|
|
||||||
volumes:
|
|
||||||
- {{ nc_root }}/redis:/data
|
|
||||||
networks:
|
|
||||||
cloud:
|
|
||||||
external: true
|
|
||||||
name: {{ nc_net_primary }}
|
|
||||||
|
|
||||||
- name: Pull redis image
|
|
||||||
community.docker.docker_compose_v2:
|
|
||||||
project_name: "{{ nc_project }}"
|
|
||||||
files: ["/tmp/redis.yml"]
|
|
||||||
pull: always
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: Recreate redis
|
|
||||||
community.docker.docker_compose_v2:
|
|
||||||
project_name: "{{ nc_project }}"
|
|
||||||
files: ["/tmp/redis.yml"]
|
|
||||||
recreate: always
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: Disable maintenance mode (if we turned it on)
|
|
||||||
community.docker.docker_container_exec:
|
|
||||||
container: "{{ nc_container }}"
|
|
||||||
user: "www-data"
|
|
||||||
command: php occ maintenance:mode --off
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: Fire one cron tick (cleanup pending jobs)
|
|
||||||
community.docker.docker_container_exec:
|
|
||||||
container: "{{ nc_container }}"
|
|
||||||
user: "www-data"
|
|
||||||
command: php -f /var/www/html/cron.php
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
---
|
|
||||||
collections:
|
|
||||||
- name: community.docker
|
|
||||||
- name: ansible.posix
|
|
||||||
57
test_sms.yml
Normal file
57
test_sms.yml
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
---
|
||||||
|
- name: Send and verify SMS delivery via internet-master.cz
|
||||||
|
hosts: localhost
|
||||||
|
gather_facts: false
|
||||||
|
vars:
|
||||||
|
sms_number: "601358865"
|
||||||
|
sms_username: "mikrotik"
|
||||||
|
sms_password_send: "jdkotzHJIOPWhjtr32D"
|
||||||
|
sms_password_recv: "jdkotzHJIOPWhjtr32D"
|
||||||
|
sms_wait_seconds: 120 # Wait 2 minutes for delivery
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- name: Generate random test string
|
||||||
|
set_fact:
|
||||||
|
random_string: "mikrotik_{{ lookup('password', '/dev/null length=8 chars=ascii_letters') }}"
|
||||||
|
|
||||||
|
- name: Send SMS message
|
||||||
|
uri:
|
||||||
|
url: "https://sms.internet-master.cz/send/?number={{ sms_number }}&message=@mikrotik@{{ random_string | urlencode }}&type=class-1&username={{ sms_username }}&password={{ sms_password_send }}"
|
||||||
|
method: GET
|
||||||
|
return_content: true
|
||||||
|
register: send_result
|
||||||
|
|
||||||
|
- name: Show send API response
|
||||||
|
debug:
|
||||||
|
var: send_result.content
|
||||||
|
|
||||||
|
- name: Wait for SMS to be delivered
|
||||||
|
pause:
|
||||||
|
seconds: "{{ sms_wait_seconds }}"
|
||||||
|
|
||||||
|
- name: Fetch received messages
|
||||||
|
uri:
|
||||||
|
url: "https://sms.internet-master.cz/receive/?username={{ sms_username }}&password={{ sms_password_recv }}"
|
||||||
|
method: GET
|
||||||
|
return_content: true
|
||||||
|
register: recv_result
|
||||||
|
|
||||||
|
- name: Parse received JSON
|
||||||
|
set_fact:
|
||||||
|
inbox: "{{ recv_result.json.inbox | default([]) }}"
|
||||||
|
|
||||||
|
- name: Check if random string message was received
|
||||||
|
set_fact:
|
||||||
|
message_found: "{{ inbox | selectattr('message', 'equalto', random_string) | list | length > 0 }}"
|
||||||
|
|
||||||
|
- name: Report result
|
||||||
|
debug:
|
||||||
|
msg: >
|
||||||
|
SMS with message '{{ random_string }}' was {{
|
||||||
|
'delivered ✅' if message_found else 'NOT delivered ❌'
|
||||||
|
}}.
|
||||||
|
|
||||||
|
- name: Fail if not delivered
|
||||||
|
fail:
|
||||||
|
msg: "Message '{{ random_string }}' not found in received inbox!"
|
||||||
|
when: not message_found
|
||||||
155
update.yml
155
update.yml
@@ -1,34 +1,165 @@
|
|||||||
- name: Update system (APT + Flatpak)
|
- name: Update system (APT + Flatpak)
|
||||||
hosts: all
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
strategy: free
|
||||||
|
serial: 2
|
||||||
|
|
||||||
become: true
|
become: true
|
||||||
become_user: root
|
become_user: root
|
||||||
become_method: sudo
|
become_method: sudo
|
||||||
|
|
||||||
|
vars:
|
||||||
|
ssh_precheck_timeout: 8
|
||||||
|
apt_async: 1800
|
||||||
|
apt_poll: 10
|
||||||
|
apt_retries: 3
|
||||||
|
apt_retry_delay: 5
|
||||||
|
flatpak_timeout: 300
|
||||||
|
flatpak_async: 600
|
||||||
|
flatpak_poll: 5
|
||||||
|
|
||||||
|
pre_tasks:
|
||||||
|
- name: Ensure SSH is reachable (skip host if not)
|
||||||
|
wait_for:
|
||||||
|
host: "{{ ansible_host | default(inventory_hostname) }}"
|
||||||
|
port: "{{ ansible_port | default(22) }}"
|
||||||
|
timeout: "{{ ssh_precheck_timeout }}"
|
||||||
|
delegate_to: localhost
|
||||||
|
register: ssh_ok
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- meta: end_host
|
||||||
|
when: ssh_ok is failed
|
||||||
|
|
||||||
|
- name: Ping with retries (handle intermittent flaps)
|
||||||
|
ping:
|
||||||
|
register: ping_r
|
||||||
|
retries: 3
|
||||||
|
delay: 3
|
||||||
|
until: ping_r is succeeded
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- meta: end_host
|
||||||
|
when: ping_r is failed
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Update APT cache
|
- name: Update APT cache (bounded + retried)
|
||||||
|
environment: { DEBIAN_FRONTEND: noninteractive }
|
||||||
apt:
|
apt:
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
|
cache_valid_time: 3600
|
||||||
|
async: "{{ apt_async }}"
|
||||||
|
poll: "{{ apt_poll }}"
|
||||||
|
register: apt_update
|
||||||
|
retries: "{{ apt_retries }}"
|
||||||
|
delay: "{{ apt_retry_delay }}"
|
||||||
|
until: apt_update is succeeded
|
||||||
|
|
||||||
- name: Upgrade all APT packages
|
- name: If APT cache update failed, try to fix dpkg and retry once
|
||||||
|
block:
|
||||||
|
- name: Fix partially configured packages
|
||||||
|
command: dpkg --configure -a
|
||||||
|
changed_when: false
|
||||||
|
- name: Retry APT cache update after dpkg fix
|
||||||
|
environment: { DEBIAN_FRONTEND: noninteractive }
|
||||||
|
apt:
|
||||||
|
update_cache: yes
|
||||||
|
async: 600
|
||||||
|
poll: 5
|
||||||
|
when: apt_update is failed
|
||||||
|
|
||||||
|
- name: Upgrade all APT packages (bounded + retried)
|
||||||
|
environment: { DEBIAN_FRONTEND: noninteractive }
|
||||||
apt:
|
apt:
|
||||||
upgrade: dist
|
upgrade: dist
|
||||||
|
async: "{{ apt_async }}"
|
||||||
|
poll: "{{ apt_poll }}"
|
||||||
|
register: apt_upgrade
|
||||||
|
retries: "{{ apt_retries }}"
|
||||||
|
delay: "{{ apt_retry_delay }}"
|
||||||
|
until: apt_upgrade is succeeded
|
||||||
|
|
||||||
|
- name: If APT upgrade failed, try to fix dpkg and retry once
|
||||||
|
block:
|
||||||
|
- name: Fix partially configured packages
|
||||||
|
command: dpkg --configure -a
|
||||||
|
changed_when: false
|
||||||
|
- name: Retry APT upgrade after dpkg fix
|
||||||
|
environment: { DEBIAN_FRONTEND: noninteractive }
|
||||||
|
apt:
|
||||||
|
upgrade: dist
|
||||||
|
async: 1200
|
||||||
|
poll: 5
|
||||||
|
when: apt_upgrade is failed
|
||||||
|
|
||||||
- name: Check if flatpak binary exists
|
- name: Check if flatpak binary exists
|
||||||
|
become: false
|
||||||
stat:
|
stat:
|
||||||
path: /usr/bin/flatpak
|
path: /usr/bin/flatpak
|
||||||
register: flatpak_bin
|
register: flatpak_bin
|
||||||
|
|
||||||
- name: Update system Flatpaks
|
- name: Update system Flatpaks (bounded; treat timeout as non-fatal)
|
||||||
shell: timeout 300 flatpak update -y
|
command: bash -lc "timeout {{ flatpak_timeout }} flatpak update -y --noninteractive"
|
||||||
register: flatpak_sys
|
register: flatpak_sys
|
||||||
failed_when: flatpak_sys.rc != 0 and flatpak_sys.rc != 124
|
async: "{{ flatpak_async }}"
|
||||||
|
poll: "{{ flatpak_poll }}"
|
||||||
|
failed_when: flatpak_sys.rc is defined and flatpak_sys.rc not in [0, 124]
|
||||||
when: flatpak_bin.stat.exists
|
when: flatpak_bin.stat.exists
|
||||||
|
|
||||||
- name: Update user Flatpaks
|
# ---- User-agnostic Flatpak updates (all non-system users) ----
|
||||||
become_user: jakub
|
|
||||||
environment:
|
- name: Get passwd database
|
||||||
XDG_RUNTIME_DIR: /run/user/1000
|
getent:
|
||||||
shell: timeout 300 flatpak update -y
|
database: passwd
|
||||||
register: flatpak_user
|
register: ge
|
||||||
failed_when: flatpak_user.rc != 0 and flatpak_user.rc != 124
|
|
||||||
|
- name: Build list of regular users (uid >= 1000, real shells)
|
||||||
|
set_fact:
|
||||||
|
regular_users: >-
|
||||||
|
{{
|
||||||
|
ge.ansible_facts.getent_passwd
|
||||||
|
| dict2items
|
||||||
|
| map(attribute='value')
|
||||||
|
| selectattr('uid', 'defined')
|
||||||
|
| selectattr('uid', '>=', 1000)
|
||||||
|
| rejectattr('shell', 'in', ['/usr/sbin/nologin','/sbin/nologin','/bin/false'])
|
||||||
|
| list
|
||||||
|
}}
|
||||||
|
when: ge is succeeded
|
||||||
|
|
||||||
|
- name: Stat per-user runtime dir if flatpak is present
|
||||||
|
stat:
|
||||||
|
path: "/run/user/{{ item.uid }}"
|
||||||
|
loop: "{{ regular_users | default([]) }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.name }}"
|
||||||
|
register: user_runtime_stats
|
||||||
|
when: flatpak_bin.stat.exists
|
||||||
|
|
||||||
|
- name: Merge runtime stats keyed by username
|
||||||
|
set_fact:
|
||||||
|
user_runtime_map: >-
|
||||||
|
{{
|
||||||
|
user_runtime_stats.results
|
||||||
|
| items2dict(key_name='item.name', value_name='stat')
|
||||||
|
}}
|
||||||
|
when: flatpak_bin.stat.exists
|
||||||
|
|
||||||
|
- name: Update user Flatpaks (use XDG_RUNTIME_DIR when available)
|
||||||
|
become_user: "{{ item.name }}"
|
||||||
|
environment: >-
|
||||||
|
{{
|
||||||
|
user_runtime_map[item.name].exists
|
||||||
|
| default(false)
|
||||||
|
| ternary({'XDG_RUNTIME_DIR': '/run/user/' ~ item.uid|string}, {})
|
||||||
|
}}
|
||||||
|
command: bash -lc "timeout {{ flatpak_timeout }} flatpak --user update -y --noninteractive"
|
||||||
|
register: flatpak_user_res
|
||||||
|
async: "{{ flatpak_async }}"
|
||||||
|
poll: "{{ flatpak_poll }}"
|
||||||
|
failed_when: flatpak_user_res.rc is defined and flatpak_user_res.rc not in [0, 124]
|
||||||
|
changed_when: "'Installing' in (flatpak_user_res.stdout | default('')) or 'Installing' in (flatpak_user_res.stderr | default('')) or 'Updating' in (flatpak_user_res.stdout | default('')) or 'Updating' in (flatpak_user_res.stderr | default(''))"
|
||||||
|
loop: "{{ regular_users | default([]) }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.name }}"
|
||||||
when: flatpak_bin.stat.exists
|
when: flatpak_bin.stat.exists
|
||||||
|
|||||||
Reference in New Issue
Block a user