Compare commits
1 Commits
main
...
transcaffe
Author | SHA1 | Date | |
---|---|---|---|
ec0bc675bd |
@ -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,6 +1,6 @@
|
||||
---
|
||||
lego_user: "lego"
|
||||
lego_version: "4.22.2"
|
||||
lego_version: "4.21.0"
|
||||
lego_instance: default
|
||||
lego_base_path: "/opt/lego"
|
||||
lego_cert_user: "acme-{{ lego_instance }}"
|
||||
|
@ -1,35 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
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
|
||||
echo "nc not found (in PATH), exiting"
|
||||
exit 1
|
||||
fi
|
||||
if [[ -n "$LEGO_HTTP_FALLBACK_PORT" ]]; then
|
||||
nc -z 127.0.0.1 $LEGO_HTTP_PORT;
|
||||
if [[ $? -eq 0 ]]; then
|
||||
LEGO_HTTP_PORT=$LEGO_HTTP_FALLBACK_PORT
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "${LEGO_PRE_RENEWAL_HOOK:-}" ]]; then
|
||||
$LEGO_PRE_RENEWAL_HOOK
|
||||
fi
|
||||
|
||||
LEGO_COMMAND_ARGS_EXPANDED=$(bash -c "echo $LEGO_COMMAND_ARGS") # This is a bit icky
|
||||
|
||||
FILES_IN_DIR=$(find "$LEGO_CERT_STORE_PATH/certificates" -type f | wc -l)
|
||||
FILES_IN_DIR=$(find "$LEGO_CERT_STORE_PATH/certificates" | wc -l)
|
||||
if [[ $FILES_IN_DIR -gt 2 ]]; then
|
||||
$LEGO_BINARY $LEGO_COMMAND_ARGS_EXPANDED renew --days=$LEGO_CERT_DAYS_TO_RENEW
|
||||
else
|
||||
$LEGO_BINARY $LEGO_COMMAND_ARGS_EXPANDED run
|
||||
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
|
||||
$LEGO_POST_RENEWAL_HOOK
|
||||
fi
|
||||
ls "$LEGO_CERT_STORE_PATH/certificates" | xargs -I{} -n 1 chmod "$LEGO_CERT_MODE" "$LEGO_CERT_STORE_PATH/certificates/{}"
|
||||
ls "$LEGO_CERT_STORE_PATH/certificates" | xargs -I{} -n 1 chown "$LEGO_CERT_USER":"$LEGO_CERT_GROUP" "$LEGO_CERT_STORE_PATH/certificates/{}"
|
||||
|
@ -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-03T14-56-28Z"
|
||||
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.4"
|
||||
nginx_version: "1.27.2"
|
||||
nginx_flavour: alpine
|
||||
nginx_base_path: /opt/nginx
|
||||
nginx_config_file: "{{ nginx_base_path }}/nginx.conf"
|
||||
|
@ -1,37 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
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
|
||||
sleep 1;
|
||||
|
||||
echo "Attempting to remove lock if present"
|
||||
restic unlock
|
||||
sleep 2
|
||||
|
||||
echo "Start backup on ${@:1}"
|
||||
restic --verbose --retry-lock=${RESTIC_RETRY_LOCK:-5m} backup "${@:1}"
|
||||
sleep 2
|
||||
|
||||
echo "Forget and prune old snapshots"
|
||||
restic forget --prune --retry-lock=${RESTIC_RETRY_LOCK:-5m} \
|
||||
--keep-within=${RESTIC_FORGET_KEEP_WITHIN:-1d} \
|
||||
--keep-hourly=${RESTIC_FORGET_KEEP_HOURLY:-6} \
|
||||
--keep-daily=${RESTIC_FORGET_KEEP_DAILY:-2} \
|
||||
--keep-weekly=${RESTIC_FORGET_KEEP_WEEKLY:-7} \
|
||||
--keep-monthly=${RESTIC_FORGET_KEEP_MONTHLY:-4} \
|
||||
--verbose
|
||||
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
|
||||
|
||||
echo "Check repository"
|
||||
restic check
|
@ -1,12 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
RESTIC_JSON=$(</dev/stdin)
|
||||
|
||||
echo $RESTIC_JSON | jq -r '.[]
|
||||
| {
|
||||
"hostname": .hostname,
|
||||
"username": .username,
|
||||
"short_id": .short_id,
|
||||
"time": ((((.time | split(".")[0]) + "Z") | fromdate) - (3600 * (.time | split("+")[1] | split(":")[0] | tonumber + 1))),
|
||||
"paths": .paths[]
|
||||
} | "restic_snapshots{hostname=\"\(.hostname)\",username=\"\(.username)\",short_id=\"\(.short_id)\",paths=\"\(.paths)\"} \(.time)"'
|
16
roles/user/README.md
Normal file
16
roles/user/README.md
Normal file
@ -0,0 +1,16 @@
|
||||
# `finallycoffee.base.user` ansible role
|
||||
|
||||
## Examples
|
||||
```yaml
|
||||
- hosts: all
|
||||
roles:
|
||||
- role: finallycoffee.base.user
|
||||
vars:
|
||||
users:
|
||||
- name: root
|
||||
- name: alice
|
||||
- name: bob
|
||||
state: present
|
||||
- name: eve
|
||||
state: absent
|
||||
```
|
2
roles/user/defaults/main.yml
Normal file
2
roles/user/defaults/main.yml
Normal file
@ -0,0 +1,2 @@
|
||||
---
|
||||
users: []
|
32
roles/user/tasks/configure-user.yml
Normal file
32
roles/user/tasks/configure-user.yml
Normal file
@ -0,0 +1,32 @@
|
||||
---
|
||||
- name: Ensure user '{{ user.name }}' is {{ user.state }}
|
||||
ansible.builtin.user:
|
||||
name: "{{ user.name }}"
|
||||
state: "{{ user.state }}"
|
||||
system: "{{ user.system | default(false, true) }}"
|
||||
home: "{{ user.home | default(omit, true) }}"
|
||||
create_home: "{{ user.create_home | default(true, true) }}"
|
||||
comment: "{{ user.comment | default(user.gecos | default(omit, true), true) }}"
|
||||
|
||||
- name: Ensure SSH authorized keys for '{{ user.name }}' are {{ user.state }}
|
||||
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.key }}"
|
||||
comment: "{{ user.name }}-{{ key.comment }}"
|
||||
loop: "{{ user.authorized_keys }}"
|
||||
loop_control:
|
||||
loop_var: key
|
||||
label: "{{ user.name }}-{{ key.comment }}"
|
8
roles/user/tasks/main.yml
Normal file
8
roles/user/tasks/main.yml
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
- name: Ensure users are configured
|
||||
ansible.builtin.include_tasks:
|
||||
file: "configure-user.yml"
|
||||
loop: "{{ users }}"
|
||||
loop_control:
|
||||
loop_var: user
|
||||
label: "{{ user.name }}"
|
Loading…
x
Reference in New Issue
Block a user