Compare commits
	
		
			1 Commits
		
	
	
		
			transcaffe
			...
			a3f740d74e
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						a3f740d74e
	
				 | 
					
					
						
@@ -1,12 +1,12 @@
 | 
			
		||||
namespace: finallycoffee
 | 
			
		||||
name: base
 | 
			
		||||
version: 0.2.1
 | 
			
		||||
version: 0.2.0
 | 
			
		||||
readme: README.md
 | 
			
		||||
authors:
 | 
			
		||||
- transcaffeine <transcaffeine@finally.coffee>
 | 
			
		||||
description: Roles for base services which are common dependencies other services like databases
 | 
			
		||||
dependencies:
 | 
			
		||||
  "community.docker": "^4.2.0"
 | 
			
		||||
  "community.docker": "^3.0.0"
 | 
			
		||||
license_file: LICENSE.md
 | 
			
		||||
build_ignore:
 | 
			
		||||
- '*.tar.gz'
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
- name: Configure user accounts
 | 
			
		||||
  hosts: "{{ user_hosts | default('all', true) }}"
 | 
			
		||||
  become: "{{ user_role_become | default(false, true) }}"
 | 
			
		||||
  gather_facts: "{{ user_role_gather_facts | default(false, true) }}"
 | 
			
		||||
  roles:
 | 
			
		||||
    - role: finallycoffee.base.user
 | 
			
		||||
@@ -1,7 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
docker_state: "present"
 | 
			
		||||
docker_daemon_config: ~
 | 
			
		||||
docker_daemon_config_file: "/etc/docker/daemon.json"
 | 
			
		||||
docker_daemon_config_file_mode: "0644"
 | 
			
		||||
docker_daemon_config_owner: root
 | 
			
		||||
docker_daemon_config_group: "{{ docker_daemon_config_owner }}"
 | 
			
		||||
@@ -1,5 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
docker_systemd_service_name: "docker.service"
 | 
			
		||||
docker_systemd_service_state: >-2
 | 
			
		||||
  {{ (docker_state == 'present') | ternary('started', 'stopped') }}
 | 
			
		||||
docker_systemd_service_enabled: "{{ (docker_state == 'present') }}"
 | 
			
		||||
@@ -1,6 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
- name: Restart docker daemon
 | 
			
		||||
  ansible.builtin.systemd_service:
 | 
			
		||||
    name: "{{ docker_systemd_service_name }}"
 | 
			
		||||
    state: "restarted"
 | 
			
		||||
  listen: "docker-restart"
 | 
			
		||||
@@ -1,18 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
- name: Ensure config directory '{{ docker_daemon_config_file | dirname }}' is present
 | 
			
		||||
  ansible.builtin.file:
 | 
			
		||||
    path: "{{ docker_daemon_config_file | dirname }}"
 | 
			
		||||
    state: "directory"
 | 
			
		||||
    mode: "0755"
 | 
			
		||||
    owner: "{{ docker_daemon_config_owner }}"
 | 
			
		||||
    group: "{{ docker_daemon_config_group }}"
 | 
			
		||||
 | 
			
		||||
- name: Configure docker daemon using '{{ docker_daemon_config_file }}'
 | 
			
		||||
  ansible.builtin.copy:
 | 
			
		||||
    content: "{{ docker_daemon_config | to_json }}"
 | 
			
		||||
    dest: "{{ docker_daemon_config_file }}"
 | 
			
		||||
    mode: "{{ docker_daemon_config_file_mode }}"
 | 
			
		||||
    owner: "{{ docker_daemon_config_owner }}"
 | 
			
		||||
    group: "{{ docker_daemon_config_group }}"
 | 
			
		||||
  when: docker_daemon_config | string | length > 0
 | 
			
		||||
  notify: docker-restart
 | 
			
		||||
@@ -1,29 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
- name: Check if target OS is supported
 | 
			
		||||
  ansible.builtin.fail:
 | 
			
		||||
    msg: >-2
 | 
			
		||||
      OS Family '{{ docker_os_family }}' is not supported!
 | 
			
		||||
  when: docker_os_family not in docker_supported_os_families
 | 
			
		||||
  vars:
 | 
			
		||||
    docker_os_family: "{{ ansible_os_family | lower }}"
 | 
			
		||||
 | 
			
		||||
- name: Ensure docker is {{ docker_state }} on {{ ansible_os_family }}-family
 | 
			
		||||
  ansible.builtin.include_tasks:
 | 
			
		||||
    file: "install-{{ ansible_os_family | lower }}.yml"
 | 
			
		||||
 | 
			
		||||
- name: Configure docker daemon
 | 
			
		||||
  ansible.builtin.include_tasks:
 | 
			
		||||
    file: "configure.yml"
 | 
			
		||||
  when: docker_state == 'present'
 | 
			
		||||
 | 
			
		||||
- name: Ensure docker daemon is {{ docker_systemd_service_enabled | ternary('enabled', 'disabled') }}
 | 
			
		||||
  ansible.builtin.systemd_service:
 | 
			
		||||
    name: "{{ docker_systemd_service_name }}"
 | 
			
		||||
    enabled: "{{ docker_systemd_service_enabled }}"
 | 
			
		||||
  when: ansible_facts['service_mgr'] == 'systemd'
 | 
			
		||||
 | 
			
		||||
- name: Ensure docker daemon is {{ docker_systemd_service_state }}
 | 
			
		||||
  ansible.builtin.systemd_service:
 | 
			
		||||
    name: "{{ docker_systemd_service_name }}"
 | 
			
		||||
    state: "{{ docker_systemd_service_state }}"
 | 
			
		||||
  when: ansible_facts['service_mgr'] == 'systemd'
 | 
			
		||||
@@ -1,3 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
docker_supported_os_families:
 | 
			
		||||
  - 'debian'
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
---
 | 
			
		||||
lego_user: "lego"
 | 
			
		||||
lego_version: "4.23.0"
 | 
			
		||||
lego_version: "4.22.2"
 | 
			
		||||
lego_instance: default
 | 
			
		||||
lego_base_path: "/opt/lego"
 | 
			
		||||
lego_cert_user: "acme-{{ lego_instance }}"
 | 
			
		||||
 
 | 
			
		||||
@@ -3,8 +3,8 @@ set -euo pipefail
 | 
			
		||||
 | 
			
		||||
LEGO_BINARY=$(/usr/bin/env which lego)
 | 
			
		||||
 | 
			
		||||
if [[ -n "${LEGO_HTTP_FALLBACK_PORT:-}" ]]; then
 | 
			
		||||
  if ! nc_binary="$(type -p 'nc')" || [[ -z $nc_binary ]]; then
 | 
			
		||||
if [[ -n "$LEGO_HTTP_FALLBACK_PORT" ]]; then
 | 
			
		||||
  if ! nc_binary="$(type -p \"nc\")" || [[ -z $nc_binary ]]; then
 | 
			
		||||
    echo "nc not found (in PATH), exiting"
 | 
			
		||||
    exit 1
 | 
			
		||||
  fi
 | 
			
		||||
@@ -14,7 +14,7 @@ if [[ -n "${LEGO_HTTP_FALLBACK_PORT:-}" ]]; then
 | 
			
		||||
  fi
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if [[ -n "${LEGO_PRE_RENEWAL_HOOK:-}" ]]; then
 | 
			
		||||
if [[ -n "$LEGO_PRE_RENEWAL_HOOK" ]]; then
 | 
			
		||||
  $LEGO_PRE_RENEWAL_HOOK
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
@@ -30,6 +30,6 @@ fi
 | 
			
		||||
find "$LEGO_CERT_STORE_PATH/certificates" -type f | xargs -I{} -n 1 chmod "$LEGO_CERT_MODE" "{}"
 | 
			
		||||
find "$LEGO_CERT_STORE_PATH/certificates" -type f | xargs -I{} -n 1 chown "${LEGO_CERT_USER}:${LEGO_CERT_GROUP}" "{}"
 | 
			
		||||
 | 
			
		||||
if [[ -n "${LEGO_POST_RENEWAL_HOOK:-}" ]]; then
 | 
			
		||||
if [[ -n "$LEGO_POST_RENEWAL_HOOK" ]]; then
 | 
			
		||||
  $LEGO_POST_RENEWAL_HOOK
 | 
			
		||||
fi
 | 
			
		||||
 
 | 
			
		||||
@@ -25,44 +25,35 @@
 | 
			
		||||
      - "{{ lego_cert_group }}"
 | 
			
		||||
    append: true
 | 
			
		||||
 | 
			
		||||
- name: Check if lego is present
 | 
			
		||||
  ansible.builtin.command:
 | 
			
		||||
    cmd: which lego
 | 
			
		||||
  changed_when: false
 | 
			
		||||
  failed_when: false
 | 
			
		||||
  register: lego_binary_info
 | 
			
		||||
  check_mode: false
 | 
			
		||||
 | 
			
		||||
- name: Check which version of lego is present
 | 
			
		||||
  ansible.builtin.command:
 | 
			
		||||
    cmd: "lego --version"
 | 
			
		||||
  changed_when: false
 | 
			
		||||
  failed_when: false
 | 
			
		||||
  register: lego_binary_version_info
 | 
			
		||||
  when: lego_binary_info.rc == 0
 | 
			
		||||
  check_mode: false
 | 
			
		||||
 | 
			
		||||
- name: Ensure lego is installed
 | 
			
		||||
  when: (lego_binary_info.rc != 0) or (lego_version not in lego_binary_version_info.stdout)
 | 
			
		||||
  block:
 | 
			
		||||
    - name: Check if lego is present
 | 
			
		||||
      ansible.builtin.command:
 | 
			
		||||
        cmd: which lego
 | 
			
		||||
      changed_when: false
 | 
			
		||||
      failed_when: false
 | 
			
		||||
      register: lego_binary_info
 | 
			
		||||
 | 
			
		||||
    - name: Download lego from source
 | 
			
		||||
      ansible.builtin.get_url:
 | 
			
		||||
        url: "{{ lego_release_archive_url }}"
 | 
			
		||||
        url_username: "{{ lego_release_archive_url_username | default(omit) }}"
 | 
			
		||||
        url_password: "{{ lego_release_archive_url_password | default(omit) }}"
 | 
			
		||||
        dest: "{{ lego_release_archive_file_path }}"
 | 
			
		||||
      when: lego_binary_info.rc != 0
 | 
			
		||||
 | 
			
		||||
    - name: Create folder to uncompress into
 | 
			
		||||
      ansible.builtin.file:
 | 
			
		||||
        dest: "{{ lego_release_archive_path }}"
 | 
			
		||||
        state: directory
 | 
			
		||||
      when: lego_binary_info.rc != 0
 | 
			
		||||
 | 
			
		||||
    - name: Uncompress lego source archive
 | 
			
		||||
      ansible.builtin.unarchive:
 | 
			
		||||
        src: "{{ lego_release_archive_file_path }}"
 | 
			
		||||
        dest: "{{ lego_release_archive_path }}"
 | 
			
		||||
        remote_src: true
 | 
			
		||||
      ignore_errors: "{{ ansible_check_mode }}"
 | 
			
		||||
      when: lego_binary_info.rc != 0
 | 
			
		||||
 | 
			
		||||
    - name: Ensure lego binary is present in PATH
 | 
			
		||||
      ansible.builtin.copy:
 | 
			
		||||
@@ -70,7 +61,14 @@
 | 
			
		||||
        dest: "/usr/local/bin/lego"
 | 
			
		||||
        mode: "u+rwx,g+rx,o+rx"
 | 
			
		||||
        remote_src: true
 | 
			
		||||
      ignore_errors: "{{ ansible_check_mode }}"
 | 
			
		||||
      when: lego_binary_info.rc != 0
 | 
			
		||||
 | 
			
		||||
    - name: Ensure lego is allowed to bind to ports < 1024
 | 
			
		||||
      community.general.capabilities:
 | 
			
		||||
        path: "/usr/local/bin/lego"
 | 
			
		||||
        capability: "cap_net_bind_service+ep"
 | 
			
		||||
        state: present
 | 
			
		||||
      when: lego_binary_allow_net_bind_service
 | 
			
		||||
 | 
			
		||||
    - name: Ensure intermediate data is gone
 | 
			
		||||
      ansible.builtin.file:
 | 
			
		||||
@@ -79,13 +77,7 @@
 | 
			
		||||
      loop:
 | 
			
		||||
        - "{{ lego_release_archive_path }}"
 | 
			
		||||
        - "{{ lego_release_archive_file_path }}"
 | 
			
		||||
 | 
			
		||||
    - name: Ensure lego is allowed to bind to ports < 1024
 | 
			
		||||
      community.general.capabilities:
 | 
			
		||||
        path: "/usr/local/bin/lego"
 | 
			
		||||
        capability: "cap_net_bind_service+ep"
 | 
			
		||||
        state: present
 | 
			
		||||
      when: lego_binary_allow_net_bind_service
 | 
			
		||||
      when: lego_binary_info.rc != 0
 | 
			
		||||
 | 
			
		||||
- name: Ensure lego base path exists
 | 
			
		||||
  ansible.builtin.file:
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,17 @@
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
minio_user: ~
 | 
			
		||||
minio_data_path: /opt/minio
 | 
			
		||||
 | 
			
		||||
minio_create_user: false
 | 
			
		||||
minio_manage_host_filesystem: false
 | 
			
		||||
 | 
			
		||||
minio_root_username: root
 | 
			
		||||
minio_root_password: ~
 | 
			
		||||
 | 
			
		||||
minio_container_name: minio
 | 
			
		||||
minio_container_image_name: "docker.io/minio/minio"
 | 
			
		||||
minio_container_image_tag: "RELEASE.2025-04-08T15-41-24Z"
 | 
			
		||||
minio_container_image_name: docker.io/minio/minio
 | 
			
		||||
minio_container_image_tag: latest
 | 
			
		||||
minio_container_image: "{{ minio_container_image_name }}:{{ minio_container_image_tag }}"
 | 
			
		||||
minio_container_networks: []
 | 
			
		||||
minio_container_ports: []
 | 
			
		||||
@@ -24,8 +34,6 @@ minio_container_command:
 | 
			
		||||
  - ":{{ minio_container_listen_port_console }}"
 | 
			
		||||
minio_container_restart_policy: "unless-stopped"
 | 
			
		||||
minio_container_image_force_source: "{{ (minio_container_image_tag == 'latest')|bool }}"
 | 
			
		||||
minio_container_state: >-2
 | 
			
		||||
  {{ (minio_state == 'present') | ternary('started', 'absent') }}
 | 
			
		||||
 | 
			
		||||
minio_container_listen_port_api: 9000
 | 
			
		||||
minio_container_listen_port_console: 8900
 | 
			
		||||
@@ -1,12 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
minio_user: ~
 | 
			
		||||
minio_data_path: /opt/minio
 | 
			
		||||
 | 
			
		||||
minio_create_user: false
 | 
			
		||||
minio_manage_host_filesystem: false
 | 
			
		||||
 | 
			
		||||
minio_root_username: root
 | 
			
		||||
minio_root_password: ~
 | 
			
		||||
 | 
			
		||||
minio_state: present
 | 
			
		||||
minio_deployment_method: docker
 | 
			
		||||
@@ -1,29 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
- name: Ensure filesystem mounts ({{ minio_data_path }}) for container volumes are present
 | 
			
		||||
  ansible.builtin.file:
 | 
			
		||||
    path: "{{ minio_data_path }}"
 | 
			
		||||
    state: directory
 | 
			
		||||
    user: "{{ minio_user|default(omit, True) }}"
 | 
			
		||||
    group: "{{ minio_user|default(omit, True) }}"
 | 
			
		||||
  when: minio_manage_host_filesystem
 | 
			
		||||
 | 
			
		||||
- name: Ensure container image '{{ minio_container_image }}' is {{ minio_state }}
 | 
			
		||||
  community.docker.docker_image:
 | 
			
		||||
    name: "{{ minio_container_image }}"
 | 
			
		||||
    state: "{{ minio_state }}"
 | 
			
		||||
    source: pull
 | 
			
		||||
    force_source: "{{ minio_container_image_force_source }}"
 | 
			
		||||
 | 
			
		||||
- name: Ensure container '{{ minio_container_name }}' is {{ minio_container_state }}
 | 
			
		||||
  community.docker.docker_container:
 | 
			
		||||
    name: "{{ minio_container_name }}"
 | 
			
		||||
    image: "{{ minio_container_image }}"
 | 
			
		||||
    volumes: "{{ minio_container_volumes }}"
 | 
			
		||||
    env: "{{ minio_container_env }}"
 | 
			
		||||
    labels: "{{ minio_container_labels }}"
 | 
			
		||||
    networks: "{{ minio_container_networks }}"
 | 
			
		||||
    ports: "{{ minio_container_ports }}"
 | 
			
		||||
    user: "{{ minio_user|default(omit, True) }}"
 | 
			
		||||
    command: "{{ minio_container_command }}"
 | 
			
		||||
    restart_policy: "{{ minio_container_restart_policy }}"
 | 
			
		||||
    state: "{{ minio_container_state }}"
 | 
			
		||||
@@ -1,25 +1,37 @@
 | 
			
		||||
---
 | 
			
		||||
- name: Ensure 'minio_state' is valid
 | 
			
		||||
  ansible.builtin.fail:
 | 
			
		||||
    msg: >-
 | 
			
		||||
      Unsupported state '{{ minio_state }}'!
 | 
			
		||||
      Supported states are {{ minio_states | join(', ') }}.
 | 
			
		||||
  when: minio_state not in minio_states
 | 
			
		||||
 | 
			
		||||
- name: Ensure 'minio_deployment_method' is valid
 | 
			
		||||
  ansible.builtin.fail:
 | 
			
		||||
    msg: >-
 | 
			
		||||
      Unsupported state '{{ minio_deployment_method }}'!
 | 
			
		||||
      Supported states are {{ minio_deployment_methods | join(', ') }}.
 | 
			
		||||
  when: minio_deployment_method not in minio_deployment_methods
 | 
			
		||||
 | 
			
		||||
- name: Ensure minio run user is {{ minio_state }}
 | 
			
		||||
  ansible.builtin.user:
 | 
			
		||||
- name: Ensure minio run user is present
 | 
			
		||||
  user:
 | 
			
		||||
    name: "{{ minio_user }}"
 | 
			
		||||
    state: "{{ minio_state }}"
 | 
			
		||||
    system: true
 | 
			
		||||
    state: present
 | 
			
		||||
    system: yes
 | 
			
		||||
  when: minio_create_user
 | 
			
		||||
 | 
			
		||||
- name: Deploy minio using {{ minio_deployment_method }}
 | 
			
		||||
  ansible.builtin.include_tasks:
 | 
			
		||||
    file: "deploy-{{ minio_deployment_method }}.yml"
 | 
			
		||||
- name: Ensure filesystem mounts ({{ minio_data_path }}) for container volumes are present
 | 
			
		||||
  file:
 | 
			
		||||
    path: "{{ minio_data_path }}"
 | 
			
		||||
    state: directory
 | 
			
		||||
    user: "{{ minio_user|default(omit, True) }}"
 | 
			
		||||
    group: "{{ minio_user|default(omit, True) }}"
 | 
			
		||||
  when: minio_manage_host_filesystem
 | 
			
		||||
 | 
			
		||||
- name: Ensure container image for minio is present
 | 
			
		||||
  community.docker.docker_image:
 | 
			
		||||
    name: "{{ minio_container_image }}"
 | 
			
		||||
    state: present
 | 
			
		||||
    source: pull
 | 
			
		||||
    force_source: "{{ minio_container_image_force_source }}"
 | 
			
		||||
 | 
			
		||||
- name: Ensure container {{ minio_container_name }} is running
 | 
			
		||||
  docker_container:
 | 
			
		||||
    name: "{{ minio_container_name }}"
 | 
			
		||||
    image: "{{ minio_container_image }}"
 | 
			
		||||
    volumes: "{{ minio_container_volumes }}"
 | 
			
		||||
    env: "{{ minio_container_env }}"
 | 
			
		||||
    labels: "{{ minio_container_labels }}"
 | 
			
		||||
    networks: "{{ minio_container_networks }}"
 | 
			
		||||
    ports: "{{ minio_container_ports }}"
 | 
			
		||||
    user: "{{ minio_user|default(omit, True) }}"
 | 
			
		||||
    command: "{{ minio_container_command }}"
 | 
			
		||||
    restart_policy: "{{ minio_container_restart_policy }}"
 | 
			
		||||
    state: started
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,5 @@
 | 
			
		||||
---
 | 
			
		||||
minio_states:
 | 
			
		||||
  - present
 | 
			
		||||
  - absent
 | 
			
		||||
minio_deployment_methods:
 | 
			
		||||
  - docker
 | 
			
		||||
 | 
			
		||||
minio_container_volumes: "{{ minio_container_base_volumes + minio_container_extra_volumes }}"
 | 
			
		||||
 | 
			
		||||
minio_container_env: "{{ minio_container_base_env | combine(minio_container_extra_env) }}"
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
---
 | 
			
		||||
nginx_version: "1.27.5"
 | 
			
		||||
nginx_version: "1.27.3"
 | 
			
		||||
nginx_flavour: alpine
 | 
			
		||||
nginx_base_path: /opt/nginx
 | 
			
		||||
nginx_config_file: "{{ nginx_base_path }}/nginx.conf"
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,4 @@
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
restic_repo_url: ~
 | 
			
		||||
restic_repo_password: ~
 | 
			
		||||
restic_s3_key_id: ~
 | 
			
		||||
@@ -8,6 +7,8 @@ restic_s3_access_key: ~
 | 
			
		||||
restic_backup_paths: []
 | 
			
		||||
restic_backup_stdin_command: ~
 | 
			
		||||
restic_backup_stdin_command_filename: ~
 | 
			
		||||
restic_backup_generate_metrics_command: >-2
 | 
			
		||||
  {{ restic_script_generate_snapshot_metrics }}
 | 
			
		||||
 | 
			
		||||
restic_policy_keep_all_within: 1d
 | 
			
		||||
restic_policy_keep_hourly: 12
 | 
			
		||||
@@ -18,6 +19,8 @@ restic_policy_keep_yearly: 5
 | 
			
		||||
restic_policy_backup_frequency: hourly
 | 
			
		||||
 | 
			
		||||
restic_base_environment:
 | 
			
		||||
  RESTIC_REPOSITORY: "{{ restic_repo_url }}"
 | 
			
		||||
  RESTIC_PASSWORD: "{{ restic_password }}"
 | 
			
		||||
  RESTIC_JOBNAME: "{{ restic_job_name | default('unknown') }}"
 | 
			
		||||
  RESTIC_FORGET_KEEP_WITHIN: "{{ restic_policy_keep_all_within }}"
 | 
			
		||||
  RESTIC_FORGET_KEEP_HOURLY: "{{ restic_policy_keep_hourly }}"
 | 
			
		||||
@@ -25,6 +28,7 @@ restic_base_environment:
 | 
			
		||||
  RESTIC_FORGET_KEEP_WEEKLY: "{{ restic_policy_keep_weekly }}"
 | 
			
		||||
  RESTIC_FORGET_KEEP_MONTHLY: "{{ restic_policy_keep_monthly }}"
 | 
			
		||||
  RESTIC_FORGET_KEEP_YEARLY: "{{ restic_policy_keep_yearly }}"
 | 
			
		||||
  RESTIC_GENERATE_SNAPSHOT_METRICS_COMMAND: "{{ restic_backup_generate_metrics_command }}"
 | 
			
		||||
 | 
			
		||||
restic_s3_environment:
 | 
			
		||||
  AWS_ACCESS_KEY_ID: "{{ restic_s3_key_id }}"
 | 
			
		||||
@@ -33,8 +37,8 @@ restic_s3_environment:
 | 
			
		||||
restic_complete_environment: >-
 | 
			
		||||
  {{
 | 
			
		||||
    restic_base_environment
 | 
			
		||||
    | combine((restic_s3_environment
 | 
			
		||||
      if (restic_s3_key_id and restic_s3_access_key) else {}) | default({}))
 | 
			
		||||
    | combine((restic_s3_environment | default({}))
 | 
			
		||||
      if (restic_s3_key_id and restic_s3_access_key) else {})
 | 
			
		||||
    | combine(restic_environment | default({}))
 | 
			
		||||
  }}
 | 
			
		||||
 | 
			
		||||
@@ -46,15 +50,3 @@ restic_policy:
 | 
			
		||||
  monthly: "{{ restic_policy_keep_monthly }}"
 | 
			
		||||
  yearly: "{{ restic_policy_keep_yearly }}"
 | 
			
		||||
  frequency: "{{ restic_policy_backup_frequency }}"
 | 
			
		||||
 | 
			
		||||
restic_user: root
 | 
			
		||||
restic_create_user: false
 | 
			
		||||
restic_start_job_on_unit_change: false
 | 
			
		||||
 | 
			
		||||
restic_job_name: ~
 | 
			
		||||
restic_job_description: "Restic backup job for {{ restic_job_name }}"
 | 
			
		||||
restic_systemd_unit_naming_scheme: "restic.{{ restic_job_name }}"
 | 
			
		||||
restic_systemd_working_directory: /tmp
 | 
			
		||||
restic_systemd_syslog_identifier: "restic-{{ restic_job_name }}"
 | 
			
		||||
 | 
			
		||||
restic_package_name: restic
 | 
			
		||||
							
								
								
									
										15
									
								
								roles/restic/defaults/main/main.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								roles/restic/defaults/main/main.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
---
 | 
			
		||||
restic_user: root
 | 
			
		||||
restic_user_create: false
 | 
			
		||||
restic_create_user: "{{ restic_user_create }}"
 | 
			
		||||
restic_user_create_home: false
 | 
			
		||||
restic_user_system: false
 | 
			
		||||
 | 
			
		||||
restic_state: present
 | 
			
		||||
restic_version: "0.17.3"
 | 
			
		||||
restic_job_name: default
 | 
			
		||||
restic_job_state: "{{ restic_state }}"
 | 
			
		||||
restic_job_directory: "/etc/restic"
 | 
			
		||||
 | 
			
		||||
restic_package_name: restic
 | 
			
		||||
restic_script_generate_snapshot_metrics: "/opt/restic-generate-snapshot-metrics.sh"
 | 
			
		||||
							
								
								
									
										11
									
								
								roles/restic/defaults/main/systemd.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								roles/restic/defaults/main/systemd.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
---
 | 
			
		||||
restic_systemd_job_name: ~
 | 
			
		||||
restic_systemd_job_description: "Restic backup job for {{ restic_job_name }}"
 | 
			
		||||
 | 
			
		||||
restic_systemd_working_directory: /tmp
 | 
			
		||||
restic_systemd_install_wanted_by: "basic.target"
 | 
			
		||||
restic_systemd_install_default_instance: "default"
 | 
			
		||||
 | 
			
		||||
restic_systemd_start_job_on_unit_change: false
 | 
			
		||||
restic_systemd_service_exec_start: "/opt/restic-backup.sh"
 | 
			
		||||
 | 
			
		||||
@@ -6,17 +6,21 @@ if [[ -n ${RESTIC_PRE_BACKUP_HOOK-} ]]; then
 | 
			
		||||
    /bin/bash -c "$RESTIC_PRE_BACKUP_HOOK"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
echo "List existing snapshots or attempt to initialize/unlock repository"
 | 
			
		||||
restic snapshots || restic init || restic unlock
 | 
			
		||||
echo "List existing snapshots or initialize repository"
 | 
			
		||||
restic snapshots || restic init
 | 
			
		||||
sleep 1;
 | 
			
		||||
 | 
			
		||||
echo "Attempting to remove lock if present"
 | 
			
		||||
restic unlock
 | 
			
		||||
sleep 2
 | 
			
		||||
sleep 1;
 | 
			
		||||
 | 
			
		||||
echo "Start backup on ${@:1}"
 | 
			
		||||
restic --verbose --retry-lock=${RESTIC_RETRY_LOCK:-5m} backup "${@:1}"
 | 
			
		||||
sleep 2
 | 
			
		||||
sleep 1;
 | 
			
		||||
 | 
			
		||||
if [[ -n ${RESTIC_POIST_BACKUP_HOOK-} ]]; then
 | 
			
		||||
    /bin/bash -c "$RESTIC_POST_BACKUP_HOOK"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
echo "Forget and prune old snapshots"
 | 
			
		||||
restic forget --prune --retry-lock=${RESTIC_RETRY_LOCK:-5m} \
 | 
			
		||||
@@ -29,9 +33,11 @@ restic forget --prune --retry-lock=${RESTIC_RETRY_LOCK:-5m} \
 | 
			
		||||
sleep 2
 | 
			
		||||
 | 
			
		||||
echo "Generate snapshot metrics"
 | 
			
		||||
restic --json snapshots | /opt/restic-generate-snapshot-metrics.sh \
 | 
			
		||||
    > /var/lib/node_exporter/restic-snapshots-${RESTIC_JOBNAME:-unknown}.prom-src
 | 
			
		||||
sleep 2
 | 
			
		||||
if [[ -n ${RESTIC_GENERATE_SNAPSHOT_METRICS_COMMAND-} ]]; then
 | 
			
		||||
    restic --json snapshots | ${RESTIC_GENERATE_SNAPSHOT_METRICS_COMMAND} \
 | 
			
		||||
        > /var/lib/node_exporter/restic-snapshots-${RESTIC_JOBNAME:-unknown}.prom-src
 | 
			
		||||
    sleep 2;
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
echo "Check repository"
 | 
			
		||||
restic check
 | 
			
		||||
							
								
								
									
										35
									
								
								roles/restic/tasks/check.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								roles/restic/tasks/check.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
---
 | 
			
		||||
- name: Check if 'restic_state' is valid
 | 
			
		||||
  ansible.builtin.fail:
 | 
			
		||||
    msg: >-2
 | 
			
		||||
      Unknown value '{{ restic_state }}' for 'restic_state'!
 | 
			
		||||
      Supported values are {{ restic_states | join(', ') }}
 | 
			
		||||
  when: restic_state not in restic_states
 | 
			
		||||
 | 
			
		||||
- name: Ensure 'restic_job_name' is properly populated
 | 
			
		||||
  ansible.builtin.fail:
 | 
			
		||||
    msg: >-2
 | 
			
		||||
      Unsupported restic_job_name '{{ restic_job_name | string }}'!
 | 
			
		||||
  when:
 | 
			
		||||
    - not (restic_job_name | string | length > 0)
 | 
			
		||||
 | 
			
		||||
- name: Ensure either backup_paths or backup_stdin_command is populated
 | 
			
		||||
  ansible.builtin.fail:
 | 
			
		||||
    msg: >-2
 | 
			
		||||
      Setting both `restic_backup_paths` and `restic_backup_stdin_command`
 | 
			
		||||
      is not supported!
 | 
			
		||||
  when: restic_backup_paths|length > 0 and restic_backup_stdin_command and false
 | 
			
		||||
 | 
			
		||||
- name: Ensure a filename for stdin_command backup is given
 | 
			
		||||
  ansible.builtin.fail:
 | 
			
		||||
    msg: >-2
 | 
			
		||||
      `restic_backup_stdin_command` was set but no filename for the resulting
 | 
			
		||||
      output was supplied in `restic_backup_stdin_command_filename`.
 | 
			
		||||
  when: restic_backup_stdin_command and not restic_backup_stdin_command_filename
 | 
			
		||||
 | 
			
		||||
- name: Ensure backup frequency adheres to systemd's OnCalender syntax
 | 
			
		||||
  command:
 | 
			
		||||
    cmd: "systemd-analyze calendar {{ restic_policy.frequency }}"
 | 
			
		||||
  register: systemd_calender_parse_res
 | 
			
		||||
  failed_when: systemd_calender_parse_res.rc != 0
 | 
			
		||||
  changed_when: false
 | 
			
		||||
							
								
								
									
										31
									
								
								roles/restic/tasks/configure.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								roles/restic/tasks/configure.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
			
		||||
---
 | 
			
		||||
- name: Ensure systemd timer file for '{{ restic_job_name }}' is {{ restic_state }}'
 | 
			
		||||
  template:
 | 
			
		||||
    dest: "/etc/systemd/system/{{ restic_systemd_unit_naming_scheme }}.timer"
 | 
			
		||||
    src: restic.timer.j2
 | 
			
		||||
    owner: root
 | 
			
		||||
    group: root
 | 
			
		||||
    mode: "0640"
 | 
			
		||||
  when: restic_state == 'present'
 | 
			
		||||
  notify:
 | 
			
		||||
    - reload-systemd
 | 
			
		||||
 | 
			
		||||
- name: Ensure restic configuration for '{{ restic_job_name }}' is {{ restic_job_state }}
 | 
			
		||||
  ansible.builtin.template:
 | 
			
		||||
    src: "restic.conf.j2"
 | 
			
		||||
    dest: "{{ restic_job_directory }}/{{ restic_job_name }}.conf"
 | 
			
		||||
    mode: "0640"
 | 
			
		||||
  when: restic_job_state in ['present', 'masked']
 | 
			
		||||
  notify:
 | 
			
		||||
    - trigger-restic
 | 
			
		||||
 | 
			
		||||
- name: Ensure restic configuration for '{{ restic_job_name }}' is {{ restic_job_state }}
 | 
			
		||||
  ansible.builtin.file:
 | 
			
		||||
    path: "{{ restic_job_directory }}/{{ restic_job_name }}.conf"
 | 
			
		||||
    state: "{{ restic_job_state }}"
 | 
			
		||||
  when: restic_job_state not in ['present', 'masked']
 | 
			
		||||
 | 
			
		||||
- name: Flush handlers to ensure systemd knows about '{{ restic_job_name }}'
 | 
			
		||||
  meta: flush_handlers
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										48
									
								
								roles/restic/tasks/install.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								roles/restic/tasks/install.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,48 @@
 | 
			
		||||
---
 | 
			
		||||
- name: Ensure restic is installed
 | 
			
		||||
  block:
 | 
			
		||||
    - name: Ensure restic is installed via apt
 | 
			
		||||
      apt:
 | 
			
		||||
        package: restic
 | 
			
		||||
        state: latest
 | 
			
		||||
      when: ansible_os_family == 'Debian'
 | 
			
		||||
    - name: Ensure restic is installed via dnf
 | 
			
		||||
      dnf:
 | 
			
		||||
        name: restic
 | 
			
		||||
        state: latest
 | 
			
		||||
      when: ansible_os_family == 'RedHat'
 | 
			
		||||
    - name: Ensure restic is installed using the auto-detected package-manager
 | 
			
		||||
      package:
 | 
			
		||||
        name: "{{ restic_package_name }}"
 | 
			
		||||
        state: present
 | 
			
		||||
      when: ansible_os_family not in ['RedHat', 'Debian']
 | 
			
		||||
 | 
			
		||||
- name: Ensure restic backup scripts are {{ restic_state }}
 | 
			
		||||
  ansible.builtin.copy:
 | 
			
		||||
    src: "{{ script.source }}"
 | 
			
		||||
    dest: "{{ script.destination }}"
 | 
			
		||||
    mode: "{{ script.mode }}"
 | 
			
		||||
  loop:
 | 
			
		||||
    - source: restic-backup.sh
 | 
			
		||||
      destination: "{{ restic_systemd_service_exec_start }}"
 | 
			
		||||
      mode: "0510"
 | 
			
		||||
    - source: restic-snapshot-metrics.sh
 | 
			
		||||
      destination: "{{ restic_script_generate_snapshot_metrics }}"
 | 
			
		||||
      mode: "0510"
 | 
			
		||||
  loop_control:
 | 
			
		||||
    loop_var: script
 | 
			
		||||
    label: "{{ script.source }}"
 | 
			
		||||
 | 
			
		||||
- name: Ensure systemd service file for restic template unit is {{ restic_state }}
 | 
			
		||||
  ansible.builtin.template:
 | 
			
		||||
    dest: "/etc/systemd/system/restic@.service"
 | 
			
		||||
    src: "restic@.service.j2"
 | 
			
		||||
    owner: root
 | 
			
		||||
    group: root
 | 
			
		||||
    mode: "0640"
 | 
			
		||||
  when: restic_state == 'present'
 | 
			
		||||
  notify:
 | 
			
		||||
    - reload-systemd
 | 
			
		||||
    - trigger-restic
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -1,77 +1,30 @@
 | 
			
		||||
---
 | 
			
		||||
- name: Check if role input is valid
 | 
			
		||||
  ansible.builtin.include_tasks:
 | 
			
		||||
    file: check.yml
 | 
			
		||||
 | 
			
		||||
- name: Ensure {{ restic_user }} system user exists
 | 
			
		||||
  user:
 | 
			
		||||
- name: Ensure restic is {{ restic_state }}
 | 
			
		||||
  ansible.builtin.include_tasks:
 | 
			
		||||
    file: install.yml
 | 
			
		||||
 | 
			
		||||
- name: Ensure restic user '{{ restic_user }}' is {{ restic_state }}
 | 
			
		||||
  ansible.builtin.user:
 | 
			
		||||
    name: "{{ restic_user }}"
 | 
			
		||||
    state: present
 | 
			
		||||
    system: true
 | 
			
		||||
    state: "{{ restic_state }}"
 | 
			
		||||
    system: "{{ restic_user_system }}"
 | 
			
		||||
    create_home: "{{ restic_user_create_home }}"
 | 
			
		||||
  when: restic_create_user
 | 
			
		||||
 | 
			
		||||
- name: Ensure either backup_paths or backup_stdin_command is populated
 | 
			
		||||
  when: restic_backup_paths|length > 0 and restic_backup_stdin_command and false
 | 
			
		||||
  fail:
 | 
			
		||||
    msg: "Setting both `restic_backup_paths` and `restic_backup_stdin_command` is not supported"
 | 
			
		||||
 | 
			
		||||
- name: Ensure a filename for stdin_command backup is given
 | 
			
		||||
  when: restic_backup_stdin_command and not restic_backup_stdin_command_filename
 | 
			
		||||
  fail:
 | 
			
		||||
    msg: "`restic_backup_stdin_command` was set but no filename for the resulting output was supplied in `restic_backup_stdin_command_filename`"
 | 
			
		||||
 | 
			
		||||
- name: Ensure backup frequency adheres to systemd's OnCalender syntax
 | 
			
		||||
  command:
 | 
			
		||||
    cmd: "systemd-analyze calendar {{ restic_policy.frequency }}"
 | 
			
		||||
  register: systemd_calender_parse_res
 | 
			
		||||
  failed_when: systemd_calender_parse_res.rc != 0
 | 
			
		||||
  changed_when: false
 | 
			
		||||
 | 
			
		||||
- name: Ensure restic is installed
 | 
			
		||||
  block:
 | 
			
		||||
    - name: Ensure restic is installed via apt
 | 
			
		||||
      apt:
 | 
			
		||||
        package: restic
 | 
			
		||||
        state: latest
 | 
			
		||||
      when: ansible_os_family == 'Debian'
 | 
			
		||||
    - name: Ensure restic is installed via dnf
 | 
			
		||||
      dnf:
 | 
			
		||||
        name: restic
 | 
			
		||||
        state: latest
 | 
			
		||||
      when: ansible_os_family == 'RedHat'
 | 
			
		||||
    - name: Ensure restic is installed using the auto-detected package-manager
 | 
			
		||||
      package:
 | 
			
		||||
        name: "{{ restic_package_name }}"
 | 
			
		||||
        state: present
 | 
			
		||||
      when: ansible_os_family not in ['RedHat', 'Debian']
 | 
			
		||||
 | 
			
		||||
- name: Ensure systemd service file for '{{ restic_job_name }}' is templated
 | 
			
		||||
  template:
 | 
			
		||||
    dest: "/etc/systemd/system/{{ restic_systemd_unit_naming_scheme }}.service"
 | 
			
		||||
    src: restic.service.j2
 | 
			
		||||
    owner: root
 | 
			
		||||
    group: root
 | 
			
		||||
    mode: 0640
 | 
			
		||||
  notify:
 | 
			
		||||
    - reload-systemd
 | 
			
		||||
    - trigger-restic
 | 
			
		||||
 | 
			
		||||
- name: Ensure systemd service file for '{{ restic_job_name }}' is templated
 | 
			
		||||
  template:
 | 
			
		||||
    dest: "/etc/systemd/system/{{ restic_systemd_unit_naming_scheme }}.timer"
 | 
			
		||||
    src: restic.timer.j2
 | 
			
		||||
    owner: root
 | 
			
		||||
    group: root
 | 
			
		||||
    mode: 0640
 | 
			
		||||
  notify:
 | 
			
		||||
    - reload-systemd
 | 
			
		||||
 | 
			
		||||
- name: Flush handlers to ensure systemd knows about '{{ restic_job_name }}'
 | 
			
		||||
  meta: flush_handlers
 | 
			
		||||
- name: Ensure restic configuration for job is {{ restic_job_state }}
 | 
			
		||||
  ansible.builtin.include_tasks:
 | 
			
		||||
    file: "configure.yml"
 | 
			
		||||
 | 
			
		||||
- name: Ensure systemd timer for '{{ restic_job_name }}' is activated
 | 
			
		||||
  systemd:
 | 
			
		||||
  ansible.builtin.systemd:
 | 
			
		||||
    name: "{{ restic_systemd_unit_naming_scheme }}.timer"
 | 
			
		||||
    enabled: true
 | 
			
		||||
 | 
			
		||||
- name: Ensure systemd timer for '{{ restic_job_name }}' is started
 | 
			
		||||
  systemd:
 | 
			
		||||
- name: Ensure systemd timer for '{{ restic_job_name }}' is {{ restic_job_state }}
 | 
			
		||||
  ansible.builtin.systemd:
 | 
			
		||||
    name: "{{ restic_systemd_unit_naming_scheme }}.timer"
 | 
			
		||||
    state: started
 | 
			
		||||
    state: started # TODO: mask a timer?
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								roles/restic/templates/restic.conf.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								roles/restic/templates/restic.conf.j2
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
{% for kv in restic_complete_environment | dict2items %}
 | 
			
		||||
{{ kv.key }}={{ kv.value }}
 | 
			
		||||
{% endfor %}
 | 
			
		||||
@@ -1,51 +0,0 @@
 | 
			
		||||
[Unit]
 | 
			
		||||
Description={{ restic_job_description }}
 | 
			
		||||
 | 
			
		||||
[Service]
 | 
			
		||||
Type=simple
 | 
			
		||||
User={{ restic_user }}
 | 
			
		||||
WorkingDirectory={{ restic_systemd_working_directory }}
 | 
			
		||||
SyslogIdentifier={{ restic_systemd_syslog_identifier }}
 | 
			
		||||
 | 
			
		||||
Environment=RESTIC_REPOSITORY={{ restic_repo_url }}
 | 
			
		||||
Environment=RESTIC_PASSWORD={{ restic_repo_password }}
 | 
			
		||||
{% for kv in restic_complete_environment | dict2items %}
 | 
			
		||||
Environment={{ kv.key }}={{ kv.value }}
 | 
			
		||||
{% endfor %}
 | 
			
		||||
 | 
			
		||||
{% if restic_init | default(true) %}
 | 
			
		||||
ExecStartPre=-/bin/sh -c '/usr/bin/restic snapshots || /usr/bin/restic init'
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% if restic_unlock_before_backup | default(false) %}
 | 
			
		||||
ExecStartPre=-/bin/sh -c 'sleep 3 && /usr/bin/restic unlock'
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% if restic_backup_pre_hook | default(false) %}
 | 
			
		||||
ExecStartPre=-{{ restic_backup_pre_hook }}
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% if restic_backup_stdin_command %}
 | 
			
		||||
ExecStart=/bin/sh -c '{{ restic_backup_stdin_command }} | /usr/bin/restic backup \
 | 
			
		||||
	--retry-lock {{ restic_retry_lock | default('5m') }} \
 | 
			
		||||
	--verbose --stdin \
 | 
			
		||||
	--stdin-filename {{ restic_backup_stdin_command_filename }}'
 | 
			
		||||
{% else %}
 | 
			
		||||
ExecStart=/opt/restic-backup-directories.sh {{ restic_backup_paths | join(' ') }}
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% if restic_forget_prune | default(true) %}
 | 
			
		||||
ExecStartPost=/usr/bin/restic forget --prune \
 | 
			
		||||
	--retry-lock {{ restic_retry_lock | default('5m') }} \
 | 
			
		||||
	--keep-within={{ restic_policy.keep_within }} \
 | 
			
		||||
	--keep-hourly={{ restic_policy.hourly }} \
 | 
			
		||||
	--keep-daily={{ restic_policy.daily }} \
 | 
			
		||||
	--keep-weekly={{ restic_policy.weekly }} \
 | 
			
		||||
	--keep-monthly={{ restic_policy.monthly }} \
 | 
			
		||||
	--keep-yearly={{ restic_policy.yearly }}
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% if restic_list_snapshots | default(true) %}
 | 
			
		||||
ExecStartPost=-/usr/bin/restic snapshots --retry-lock {{ restic_retry_lock | default('5m') }}
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% if restic_backup_post_hook | default(false) %}
 | 
			
		||||
ExecStartPost=-{{ restic_backup_post_hook }}
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% if restic_check | default(true) %}
 | 
			
		||||
ExecStartPost=/usr/bin/restic check --retry-lock {{ restic_retry_lock | default('5m') }}
 | 
			
		||||
{% endif %}
 | 
			
		||||
							
								
								
									
										15
									
								
								roles/restic/templates/restic@.service.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								roles/restic/templates/restic@.service.j2
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
[Unit]
 | 
			
		||||
Description={{ restic_systemd_job_description }}
 | 
			
		||||
 | 
			
		||||
[Service]
 | 
			
		||||
Type=simple
 | 
			
		||||
EnvironmentFile={{ restic_job_directory }}/%i.conf
 | 
			
		||||
User={{ restic_user }}
 | 
			
		||||
WorkingDirectory={{ restic_systemd_working_directory }}
 | 
			
		||||
SyslogIdentifier={{ restic_systemd_syslog_identifier }}
 | 
			
		||||
 | 
			
		||||
ExecStart={{ restic_systemd_service_exec_start }}
 | 
			
		||||
 | 
			
		||||
[Install]
 | 
			
		||||
WantedBy={{ restic_systemd_install_wanted_by }}
 | 
			
		||||
DefaultInstance={{ restic_systemd_install_default_instance }}
 | 
			
		||||
							
								
								
									
										9
									
								
								roles/restic/vars/main.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								roles/restic/vars/main.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
---
 | 
			
		||||
restic_states:
 | 
			
		||||
  - "present"
 | 
			
		||||
  - "absent"
 | 
			
		||||
 | 
			
		||||
restic_job_states:
 | 
			
		||||
  - "present"
 | 
			
		||||
  - "masked"
 | 
			
		||||
  - "absent"
 | 
			
		||||
@@ -1,23 +0,0 @@
 | 
			
		||||
# `finallycoffee.base.user` ansible role
 | 
			
		||||
 | 
			
		||||
Provision and manage user accounts on the remote host. Supports setting user
 | 
			
		||||
home, gecos (display name) and shell.
 | 
			
		||||
 | 
			
		||||
Warning: if the users' home exists and is changed, the role will attempt to
 | 
			
		||||
move the home directory. Set `move_home` to false on the user to disable this
 | 
			
		||||
behaviour.
 | 
			
		||||
 | 
			
		||||
## Examples
 | 
			
		||||
```yaml
 | 
			
		||||
- hosts: all
 | 
			
		||||
  roles:
 | 
			
		||||
    - role: finallycoffee.base.user
 | 
			
		||||
  vars:
 | 
			
		||||
    users:
 | 
			
		||||
      - name: root
 | 
			
		||||
      - name: alice
 | 
			
		||||
      - name: bob
 | 
			
		||||
        state: present
 | 
			
		||||
      - name: eve
 | 
			
		||||
        state: absent
 | 
			
		||||
```
 | 
			
		||||
@@ -1,2 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
users: []
 | 
			
		||||
@@ -1,41 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
- name: Ensure user '{{ user.name }}' is {{ user_state }}
 | 
			
		||||
  ansible.builtin.user:
 | 
			
		||||
    name: "{{ user.name }}"
 | 
			
		||||
    state: "{{ user_state }}"
 | 
			
		||||
    system: "{{ user.system | default(false, true) }}"
 | 
			
		||||
    shell: "{{ user.shell | default(omit, true) }}"
 | 
			
		||||
    home: "{{ user.home | default(omit, true) }}"
 | 
			
		||||
    create_home: "{{ user.create_home | default(true, true) }}"
 | 
			
		||||
    move_home: "{{ user.move_home | default(true, true) }}"
 | 
			
		||||
    skeleton: >-2
 | 
			
		||||
      {{ (user.create_home | default(true, true) and 'skeleton' in user)
 | 
			
		||||
      | ternary(user.skeleton | default(''), omit) }}
 | 
			
		||||
    comment: "{{ user.comment | default(user.gecos | default(omit, true), true) }}"
 | 
			
		||||
  vars:
 | 
			
		||||
    user_state: "{{ user.state | default('present', false) }}"
 | 
			
		||||
 | 
			
		||||
- name: Ensure SSH authorized keys for '{{ user.name }}' are {{ user_state }}
 | 
			
		||||
  vars:
 | 
			
		||||
    user_state: "{{ user.state | default('present', false) }}"
 | 
			
		||||
  when:
 | 
			
		||||
    - user_state == 'present'
 | 
			
		||||
    - user.authorized_keys | default([]) | length > 0
 | 
			
		||||
  block:
 | 
			
		||||
    - name: Ensure .ssh directory for user '{{ user.name }}' exists
 | 
			
		||||
      ansible.builtin.file:
 | 
			
		||||
        path: "{{ user.home | default('/home/' + user.name) + '/.ssh' }}"
 | 
			
		||||
        state: "directory"
 | 
			
		||||
        owner: "{{ user.name }}"
 | 
			
		||||
        group: "{{ user.name }}"
 | 
			
		||||
        mode: "0700"
 | 
			
		||||
    - name: Ensure key is up to date
 | 
			
		||||
      ansible.posix.authorized_key:
 | 
			
		||||
        user: "{{ user.name }}"
 | 
			
		||||
        state: "{{ key.state | default('present', true) }}"
 | 
			
		||||
        key: "{{ key.type }} {{ key.key }}"
 | 
			
		||||
        comment: "{{ user.name }}-{{ key.comment }}"
 | 
			
		||||
      loop: "{{ user.authorized_keys }}"
 | 
			
		||||
      loop_control:
 | 
			
		||||
        loop_var: key
 | 
			
		||||
        label: "{{ user.name }}-{{ key.comment }}"
 | 
			
		||||
@@ -1,8 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
- name: Ensure users are configured
 | 
			
		||||
  ansible.builtin.include_tasks:
 | 
			
		||||
    file: "configure-user.yml"
 | 
			
		||||
  loop: "{{ users }}"
 | 
			
		||||
  loop_control:
 | 
			
		||||
    loop_var: user
 | 
			
		||||
    label: "{{ user.name }}"
 | 
			
		||||
		Reference in New Issue
	
	Block a user