forked from finallycoffee/base
Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
0771787c98 | |||
1024921a74 | |||
62263726fa | |||
ae887a1936 | |||
1e57ae1ec0 | |||
90dae1311f | |||
3733c0b7ab | |||
877c5a137a | |||
11d4b397ef | |||
76e89db5c6 | |||
4bddc95161 | |||
ed95d4fd3d | |||
788c4bada0 | |||
7ecf8778ca | |||
11fec18afc | |||
b0ba86f78e | |||
bd418a6199 | |||
60b36db8a7 | |||
9a02652d98 | |||
2c1b3cb47e | |||
114cf13871 | |||
b77c81f754 | |||
bdf1871855 | |||
9454845ea1 | |||
4e8cc9bcf2 | |||
3b9d6e19da | |||
c847046720 | |||
d7b7c59f46 |
@ -5,10 +5,6 @@
|
|||||||
This ansible collection provides various roles for installing
|
This ansible collection provides various roles for installing
|
||||||
and configuring basic system utilities like gnupg, ssh etc
|
and configuring basic system utilities like gnupg, ssh etc
|
||||||
|
|
||||||
- [`elasticsearch`](roles/elasticsearch/README.md): Deploy [elasticsearch](https://www.docker.elastic.co/r/elasticsearch/elasticsearch-oss),
|
|
||||||
a popular (distributed) search and analytics engine, mostly known by it's
|
|
||||||
letter "E" in the ELK-stack.
|
|
||||||
|
|
||||||
- [`git`](roles/git/README.md): configures git on the target system
|
- [`git`](roles/git/README.md): configures git on the target system
|
||||||
|
|
||||||
- [`gnupg`](roles/gnupg/README.md): configures gnupg on the target system
|
- [`gnupg`](roles/gnupg/README.md): configures gnupg on the target system
|
||||||
@ -16,8 +12,6 @@ and configuring basic system utilities like gnupg, ssh etc
|
|||||||
- [`lego`](roles/lego/README.md): runs [lego (LetsEncrypt Go)](https://github.com/go-acme/lego),
|
- [`lego`](roles/lego/README.md): runs [lego (LetsEncrypt Go)](https://github.com/go-acme/lego),
|
||||||
a ACME client written in go, using systemd (timers). Multi-instance capable.
|
a ACME client written in go, using systemd (timers). Multi-instance capable.
|
||||||
|
|
||||||
- [`mariadb`](roles/mariadb/README.md): runs [MariaDB Server](https://mariadb.org/), one of the world's most popular open source relational database
|
|
||||||
|
|
||||||
- [`minio`](roles/minio/README.md): Deploy [min.io](https://min.io), an
|
- [`minio`](roles/minio/README.md): Deploy [min.io](https://min.io), an
|
||||||
s3-compatible object storage server, using docker containers.
|
s3-compatible object storage server, using docker containers.
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
namespace: finallycoffee
|
namespace: finallycoffee
|
||||||
name: base
|
name: base
|
||||||
version: 0.1.2
|
version: 0.2.1
|
||||||
readme: README.md
|
readme: README.md
|
||||||
authors:
|
authors:
|
||||||
- transcaffeine <transcaffeine@finally.coffee>
|
- transcaffeine <transcaffeine@finally.coffee>
|
||||||
description: Roles for base services which are common dependencies other services like databases
|
description: Roles for base services which are common dependencies other services like databases
|
||||||
dependencies:
|
dependencies:
|
||||||
"community.docker": "^3.0.0"
|
"community.docker": "^4.2.0"
|
||||||
license_file: LICENSE.md
|
license_file: LICENSE.md
|
||||||
build_ignore:
|
build_ignore:
|
||||||
- '*.tar.gz'
|
- '*.tar.gz'
|
||||||
@ -14,9 +14,8 @@ repository: https://git.finally.coffee/finallycoffee/base
|
|||||||
issues: https://codeberg.org/finallycoffee/ansible-collection-base/issues
|
issues: https://codeberg.org/finallycoffee/ansible-collection-base/issues
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- elastic
|
|
||||||
- lego
|
- lego
|
||||||
- mariadb
|
|
||||||
- minio
|
- minio
|
||||||
- nginx
|
- nginx
|
||||||
- restic
|
- restic
|
||||||
|
- docker
|
||||||
|
6
playbooks/docker.yml
Normal file
6
playbooks/docker.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
- name: Install and configure docker daemon
|
||||||
|
hosts: "{{ docker_hosts | default('docker', true) }}"
|
||||||
|
become: "{{ docker_become | default(false, true) }}"
|
||||||
|
roles:
|
||||||
|
- role: finallycoffee.base.docker
|
7
playbooks/user.yml
Normal file
7
playbooks/user.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
- 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
|
13
roles/docker/README.md
Normal file
13
roles/docker/README.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# `finallycoffee.base.docker` ansible role
|
||||||
|
|
||||||
|
Install and configure the docker daemon.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
- `docker_daemon_config` - configuration for the docker daemon
|
||||||
|
- `docker_remove_legacy_packages` - clean up old versions of docker (see https://docs.docker.com/engine/install/debian/#uninstall-old-versions)
|
||||||
|
|
||||||
|
## Plugins
|
||||||
|
|
||||||
|
- `docker_plugin_buildx_enable` - enable the buildx plugin
|
||||||
|
- `docker_plugin_compose_enable` - enable docker compose
|
31
roles/docker/defaults/main/debian.yml
Normal file
31
roles/docker/defaults/main/debian.yml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
---
|
||||||
|
docker_apt_key_url: "https://download.docker.com/linux/debian/gpg"
|
||||||
|
docker_apt_key_id: "9DC858229FC7DD38854AE2D88D81803C0EBFCD88"
|
||||||
|
|
||||||
|
docker_apt_arch: amd64
|
||||||
|
docker_apt_release_channel: stable
|
||||||
|
docker_apt_repository_url: "https://download.docker.com/linux/debian"
|
||||||
|
docker_apt_repository: >-2
|
||||||
|
deb [arch={{ docker_apt_arch }}] {{ docker_apt_repository_url }} {{ ansible_distribution_release }} {{ docker_apt_release_channel }}
|
||||||
|
docker_apt_cli_package: "docker-ce-cli"
|
||||||
|
docker_apt_plugin_buildx_package: "docker-buildx-plugin"
|
||||||
|
docker_apt_plugin_compose_package: "docker-compose-plugin"
|
||||||
|
docker_apt_base_packages:
|
||||||
|
- "docker-ce"
|
||||||
|
- "docker-ce-cli"
|
||||||
|
- "containerd.io"
|
||||||
|
docker_apt_packages: >-2
|
||||||
|
{{
|
||||||
|
docker_apt_base_packages
|
||||||
|
+ (docker_plugin_buildx_enable | default(false)
|
||||||
|
| ternary([ docker_apt_plugin_buildx_package ], []))
|
||||||
|
+ (docker_plugin_compose_enable | default(false)
|
||||||
|
| ternary([ docker_apt_plugin_compose_package ], []))
|
||||||
|
}}
|
||||||
|
docker_apt_legacy_packages:
|
||||||
|
- "docker.io"
|
||||||
|
- "docker-compose"
|
||||||
|
- "docker-doc"
|
||||||
|
- "podman-docker"
|
||||||
|
- "containerd"
|
||||||
|
- "runc"
|
13
roles/docker/defaults/main/main.yml
Normal file
13
roles/docker/defaults/main/main.yml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
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 }}"
|
||||||
|
|
||||||
|
docker_plugin_buildx_enable: false
|
||||||
|
docker_plugin_compose_enable: false
|
||||||
|
|
||||||
|
docker_remove_legacy_packages: true
|
5
roles/docker/defaults/main/systemd.yml
Normal file
5
roles/docker/defaults/main/systemd.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
docker_systemd_service_name: "docker.service"
|
||||||
|
docker_systemd_service_state: >-2
|
||||||
|
{{ (docker_state == 'present') | ternary('started', 'stopped') }}
|
||||||
|
docker_systemd_service_enabled: "{{ (docker_state == 'present') }}"
|
6
roles/docker/handlers/main.yml
Normal file
6
roles/docker/handlers/main.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
- name: Restart docker daemon
|
||||||
|
ansible.builtin.systemd_service:
|
||||||
|
name: "{{ docker_systemd_service_name }}"
|
||||||
|
state: "restarted"
|
||||||
|
listen: "docker-restart"
|
18
roles/docker/tasks/configure.yml
Normal file
18
roles/docker/tasks/configure.yml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
- 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
|
30
roles/docker/tasks/install-debian.yml
Normal file
30
roles/docker/tasks/install-debian.yml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure legacy docker packages are removed
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: "{{ docker_apt_legacy_packages }}"
|
||||||
|
state: absent
|
||||||
|
when: docker_remove_legacy_packages
|
||||||
|
|
||||||
|
- name: Add apt key for docker repository
|
||||||
|
ansible.builtin.apt_key:
|
||||||
|
id: "{{ docker_apt_key_id }}"
|
||||||
|
url: "{{ docker_apt_key_url }}"
|
||||||
|
state: "{{ docker_state }}"
|
||||||
|
|
||||||
|
- name: Add apt repository for docker
|
||||||
|
ansible.builtin.apt_repository:
|
||||||
|
repo: "{{ docker_apt_repository }}"
|
||||||
|
state: "{{ docker_state }}"
|
||||||
|
register: docker_apt_repository_info
|
||||||
|
|
||||||
|
- name: Update apt cache if repository was newly added
|
||||||
|
ansible.builtin.apt:
|
||||||
|
update_cache: true
|
||||||
|
when:
|
||||||
|
- docker_state == 'present'
|
||||||
|
- docker_apt_repository_info.changed
|
||||||
|
|
||||||
|
- name: Install apt packages for docker
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: "{{ docker_apt_packages }}"
|
||||||
|
state: "{{ docker_state }}"
|
29
roles/docker/tasks/main.yml
Normal file
29
roles/docker/tasks/main.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
- 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'
|
3
roles/docker/vars/main.yml
Normal file
3
roles/docker/vars/main.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
docker_supported_os_families:
|
||||||
|
- 'debian'
|
@ -1,22 +0,0 @@
|
|||||||
# `finallycoffee.base.elastiscsearch`
|
|
||||||
|
|
||||||
A simple ansible role which deploys a single-node elastic container to provide
|
|
||||||
an easy way to do some indexing.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Per default, `/opt/elasticsearch/data` is used to persist data, it is
|
|
||||||
customizable by using either `elasticsearch_base_path` or `elasticsearch_data_path`.
|
|
||||||
|
|
||||||
As elasticsearch be can be quite memory heavy, the maximum amount of allowed RAM
|
|
||||||
can be configured using `elasticsearch_allocated_ram_mb`, defaulting to 512 (mb).
|
|
||||||
|
|
||||||
The cluster name and discovery type can be overridden using
|
|
||||||
`elasticsearch_config_cluster_name` (default: elastic) and
|
|
||||||
`elasticsearch_config_discovery_type` (default: single-node), should one
|
|
||||||
need a multi-node elasticsearch deployment.
|
|
||||||
|
|
||||||
Per default, no ports or networks are mapped, and explizit mapping using
|
|
||||||
either ports (`elasticsearch_container_ports`) or networks
|
|
||||||
(`elasticsearch_container_networks`) is required in order for other services
|
|
||||||
to use elastic.
|
|
@ -1,35 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
elasticsearch_version: 7.17.7
|
|
||||||
|
|
||||||
elasticsearch_base_path: /opt/elasticsearch
|
|
||||||
elasticsearch_data_path: "{{ elasticsearch_base_path }}/data"
|
|
||||||
|
|
||||||
elasticsearch_config_cluster_name: elastic
|
|
||||||
elasticsearch_config_discovery_type: single-node
|
|
||||||
elasticsearch_config_boostrap_memory_lock: true
|
|
||||||
elasticsearch_allocated_ram_mb: 512
|
|
||||||
|
|
||||||
elasticsearch_container_image_name: docker.elastic.co/elasticsearch/elasticsearch-oss
|
|
||||||
elasticsearch_container_image_tag: ~
|
|
||||||
elasticsearch_container_image: >-
|
|
||||||
{{ elasticsearch_container_image_name }}:{{ elasticsearch_container_image_tag | default(elasticsearch_version, true) }}
|
|
||||||
|
|
||||||
elasticsearch_container_name: elasticsearch
|
|
||||||
elasticsearch_container_env:
|
|
||||||
"ES_JAVA_OPTS": "-Xms{{ elasticsearch_allocated_ram_mb }}m -Xmx{{ elasticsearch_allocated_ram_mb }}m"
|
|
||||||
"cluster.name": "{{ elasticsearch_config_cluster_name }}"
|
|
||||||
"discovery.type": "{{ elasticsearch_config_discovery_type }}"
|
|
||||||
"bootstrap.memory_lock": "{{ 'true' if elasticsearch_config_boostrap_memory_lock else 'false' }}"
|
|
||||||
elasticsearch_container_user: ~
|
|
||||||
elasticsearch_container_ports: ~
|
|
||||||
elasticsearch_container_labels:
|
|
||||||
version: "{{ elasticsearch_version }}"
|
|
||||||
elasticsearch_container_ulimits:
|
|
||||||
# - "memlock:{{ (1.5 * 1024 * elasticsearch_allocated_ram_mb) | int }}:{{ (1.5 * 1024 * elasticsearch_allocated_ram_mb) | int }}"
|
|
||||||
- "memlock:-1:-1"
|
|
||||||
elasticsearch_container_volumes:
|
|
||||||
- "{{ elasticsearch_data_path }}:/usr/share/elasticsearch/data:z"
|
|
||||||
elasticsearch_container_networks: ~
|
|
||||||
elasticsearch_container_purge_networks: ~
|
|
||||||
elasticsearch_container_restart_policy: unless-stopped
|
|
@ -1,32 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
- name: Ensure host directories are present
|
|
||||||
file:
|
|
||||||
path: "{{ item }}"
|
|
||||||
state: directory
|
|
||||||
mode: "0777"
|
|
||||||
loop:
|
|
||||||
- "{{ elasticsearch_base_path }}"
|
|
||||||
- "{{ elasticsearch_data_path }}"
|
|
||||||
|
|
||||||
- name: Ensure elastic container image is present
|
|
||||||
docker_image:
|
|
||||||
name: "{{ elasticsearch_container_image }}"
|
|
||||||
state: present
|
|
||||||
source: pull
|
|
||||||
force_source: "{{ elasticsearch_container_image_tag|default(false, true)|bool }}"
|
|
||||||
|
|
||||||
- name: Ensure elastic container is running
|
|
||||||
docker_container:
|
|
||||||
name: "{{ elasticsearch_container_name }}"
|
|
||||||
image: "{{ elasticsearch_container_image }}"
|
|
||||||
env: "{{ elasticsearch_container_env | default(omit, True) }}"
|
|
||||||
user: "{{ elasticsearch_container_user | default(omit, True) }}"
|
|
||||||
ports: "{{ elasticsearch_container_ports | default(omit, True) }}"
|
|
||||||
labels: "{{ elasticsearch_container_labels | default(omit, True) }}"
|
|
||||||
volumes: "{{ elasticsearch_container_volumes }}"
|
|
||||||
ulimits: "{{ elasticsearch_container_ulimits }}"
|
|
||||||
networks: "{{ elasticsearch_container_networks | default(omit, True) }}"
|
|
||||||
purge_networks: "{{ elasticsearch_container_purge_networks | default(omit, True) }}"
|
|
||||||
restart_policy: "{{ elasticsearch_container_restart_policy }}"
|
|
||||||
state: started
|
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
lego_user: "lego"
|
lego_user: "lego"
|
||||||
lego_version: "4.18.0"
|
lego_version: "4.23.0"
|
||||||
lego_instance: default
|
lego_instance: default
|
||||||
lego_base_path: "/opt/lego"
|
lego_base_path: "/opt/lego"
|
||||||
lego_cert_user: "acme-{{ lego_instance }}"
|
lego_cert_user: "acme-{{ lego_instance }}"
|
||||||
|
@ -1,22 +1,35 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
LEGO_BINARY=$(/usr/bin/env which lego)
|
LEGO_BINARY=$(/usr/bin/env which lego)
|
||||||
|
|
||||||
if [[ -n "$LEGO_HTTP_FALLBACK_PORT" ]]; 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
|
||||||
nc -z 127.0.0.1 $LEGO_HTTP_PORT;
|
nc -z 127.0.0.1 $LEGO_HTTP_PORT;
|
||||||
if [[ $? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
LEGO_HTTP_PORT=$LEGO_HTTP_FALLBACK_PORT
|
LEGO_HTTP_PORT=$LEGO_HTTP_FALLBACK_PORT
|
||||||
fi
|
fi
|
||||||
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
|
LEGO_COMMAND_ARGS_EXPANDED=$(bash -c "echo $LEGO_COMMAND_ARGS") # This is a bit icky
|
||||||
|
|
||||||
FILES_IN_DIR=$(find "$LEGO_CERT_STORE_PATH/certificates" | wc -l)
|
FILES_IN_DIR=$(find "$LEGO_CERT_STORE_PATH/certificates" -type f | wc -l)
|
||||||
if [[ $FILES_IN_DIR -gt 2 ]]; then
|
if [[ $FILES_IN_DIR -gt 2 ]]; then
|
||||||
$LEGO_BINARY $LEGO_COMMAND_ARGS_EXPANDED renew --days=$LEGO_CERT_DAYS_TO_RENEW
|
$LEGO_BINARY $LEGO_COMMAND_ARGS_EXPANDED renew --days=$LEGO_CERT_DAYS_TO_RENEW
|
||||||
else
|
else
|
||||||
$LEGO_BINARY $LEGO_COMMAND_ARGS_EXPANDED run
|
$LEGO_BINARY $LEGO_COMMAND_ARGS_EXPANDED run
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ls "$LEGO_CERT_STORE_PATH/certificates" | xargs -I{} -n 1 chmod "$LEGO_CERT_MODE" "$LEGO_CERT_STORE_PATH/certificates/{}"
|
find "$LEGO_CERT_STORE_PATH/certificates" -type f | xargs -I{} -n 1 chmod "$LEGO_CERT_MODE" "{}"
|
||||||
ls "$LEGO_CERT_STORE_PATH/certificates" | xargs -I{} -n 1 chown "$LEGO_CERT_USER":"$LEGO_CERT_GROUP" "$LEGO_CERT_STORE_PATH/certificates/{}"
|
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
|
||||||
|
@ -25,35 +25,44 @@
|
|||||||
- "{{ lego_cert_group }}"
|
- "{{ lego_cert_group }}"
|
||||||
append: true
|
append: true
|
||||||
|
|
||||||
- name: Ensure lego is installed
|
- name: Check if lego is present
|
||||||
block:
|
ansible.builtin.command:
|
||||||
- name: Check if lego is present
|
cmd: which lego
|
||||||
ansible.builtin.command:
|
changed_when: false
|
||||||
cmd: which lego
|
failed_when: false
|
||||||
changed_when: false
|
register: lego_binary_info
|
||||||
failed_when: false
|
check_mode: false
|
||||||
register: lego_binary_info
|
|
||||||
|
|
||||||
|
- 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: Download lego from source
|
- name: Download lego from source
|
||||||
ansible.builtin.get_url:
|
ansible.builtin.get_url:
|
||||||
url: "{{ lego_release_archive_url }}"
|
url: "{{ lego_release_archive_url }}"
|
||||||
url_username: "{{ lego_release_archive_url_username | default(omit) }}"
|
url_username: "{{ lego_release_archive_url_username | default(omit) }}"
|
||||||
url_password: "{{ lego_release_archive_url_password | default(omit) }}"
|
url_password: "{{ lego_release_archive_url_password | default(omit) }}"
|
||||||
dest: "{{ lego_release_archive_file_path }}"
|
dest: "{{ lego_release_archive_file_path }}"
|
||||||
when: lego_binary_info.rc != 0
|
|
||||||
|
|
||||||
- name: Create folder to uncompress into
|
- name: Create folder to uncompress into
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
dest: "{{ lego_release_archive_path }}"
|
dest: "{{ lego_release_archive_path }}"
|
||||||
state: directory
|
state: directory
|
||||||
when: lego_binary_info.rc != 0
|
|
||||||
|
|
||||||
- name: Uncompress lego source archive
|
- name: Uncompress lego source archive
|
||||||
ansible.builtin.unarchive:
|
ansible.builtin.unarchive:
|
||||||
src: "{{ lego_release_archive_file_path }}"
|
src: "{{ lego_release_archive_file_path }}"
|
||||||
dest: "{{ lego_release_archive_path }}"
|
dest: "{{ lego_release_archive_path }}"
|
||||||
remote_src: true
|
remote_src: true
|
||||||
when: lego_binary_info.rc != 0
|
ignore_errors: "{{ ansible_check_mode }}"
|
||||||
|
|
||||||
- name: Ensure lego binary is present in PATH
|
- name: Ensure lego binary is present in PATH
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
@ -61,14 +70,7 @@
|
|||||||
dest: "/usr/local/bin/lego"
|
dest: "/usr/local/bin/lego"
|
||||||
mode: "u+rwx,g+rx,o+rx"
|
mode: "u+rwx,g+rx,o+rx"
|
||||||
remote_src: true
|
remote_src: true
|
||||||
when: lego_binary_info.rc != 0
|
ignore_errors: "{{ ansible_check_mode }}"
|
||||||
|
|
||||||
- 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
|
- name: Ensure intermediate data is gone
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
@ -77,7 +79,13 @@
|
|||||||
loop:
|
loop:
|
||||||
- "{{ lego_release_archive_path }}"
|
- "{{ lego_release_archive_path }}"
|
||||||
- "{{ lego_release_archive_file_path }}"
|
- "{{ lego_release_archive_file_path }}"
|
||||||
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 lego base path exists
|
- name: Ensure lego base path exists
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
# `finallycoffee.base.mariadb` ansible role
|
|
||||||
|
|
||||||
This role deploys a MariaDB instance in a docker container.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
The role expects the following variables to be populated with values and/or secrets:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
mariadb_root_password: #mariadb root password
|
|
||||||
mariadb_database: # name of the database to create
|
|
||||||
mariadb_username: # name of a user to auto-create and assign permission on the mariadb_database
|
|
||||||
mariadb_password: # password of the user in mariadb_username
|
|
||||||
```
|
|
||||||
|
|
||||||
## Requirements
|
|
||||||
|
|
||||||
- Docker installed
|
|
||||||
- python-docker present on target system for ansible to be able to talk with the docker API.
|
|
@ -1,32 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
mariadb_version: "10.11.9"
|
|
||||||
mariadb_base_path: /var/lib/mariadb
|
|
||||||
mariadb_data_path: "{{ mariadb_base_path }}/{{ mariadb_version }}"
|
|
||||||
|
|
||||||
mariadb_root_password: ~
|
|
||||||
mariadb_database: ~
|
|
||||||
mariadb_username: ~
|
|
||||||
mariadb_password: ~
|
|
||||||
|
|
||||||
mariadb_container_base_environment:
|
|
||||||
MARIADB_ROOT_PASSWORD: "{{ mariadb_root_password }}"
|
|
||||||
mariadb_container_extra_environment: {}
|
|
||||||
|
|
||||||
mariadb_container_name: mariadb
|
|
||||||
mariadb_container_image_name: docker.io/mariadb
|
|
||||||
mariadb_container_image_tag: ~
|
|
||||||
mariadb_container_image: "{{ mariadb_container_image_name }}:{{ mariadb_container_image_tag | default(mariadb_version, true) }}"
|
|
||||||
mariadb_container_base_volumes:
|
|
||||||
- "{{ mariadb_data_path }}:{{ mariadb_container_data_path }}:z"
|
|
||||||
mariadb_container_extra_volumes: []
|
|
||||||
mariadb_container_base_labels:
|
|
||||||
version: "{{ mariadb_version }}"
|
|
||||||
mariadb_container_extra_labels: {}
|
|
||||||
mariadb_container_restart_policy: "unless-stopped"
|
|
||||||
mariadb_container_environment: >-2
|
|
||||||
{{ mariadb_container_base_environment
|
|
||||||
| combine(mariadb_container_database_environment
|
|
||||||
if (mariadb_database and mariadb_username and mariadb_password)
|
|
||||||
else {}, recursive=True)
|
|
||||||
| combine(mariadb_container_extra_environment) }}
|
|
@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Ensure mariaDB container image is present on host
|
|
||||||
community.docker.docker_image:
|
|
||||||
name: "{{ mariadb_container_image }}"
|
|
||||||
state: present
|
|
||||||
source: pull
|
|
||||||
|
|
||||||
- name: Ensure mariaDB {{ mariadb_version }} is running as '{{ mariadb_container_name }}'
|
|
||||||
community.docker.docker_container:
|
|
||||||
name: "{{ mariadb_container_name }}"
|
|
||||||
image: "{{ mariadb_container_image }}"
|
|
||||||
env: "{{ mariadb_container_environment }}"
|
|
||||||
ports: "{{ mariadb_container_ports }}"
|
|
||||||
labels: "{{ mariadb_container_labels }}"
|
|
||||||
volumes: "{{ mariadb_container_volumes }}"
|
|
||||||
networks: "{{ mariadb_container_networks | default(omit, true) }}"
|
|
||||||
etc_hosts: "{{ mariadb_container_etc_hosts | default(omit, true) }}"
|
|
||||||
purge_networks: "{{ mariadb_container_purge_networks | default(omit, true) }}"
|
|
||||||
restart_policy: "{{ mariadb_container_restart_policy }}"
|
|
||||||
state: started
|
|
@ -1,10 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
mariadb_container_database_environment:
|
|
||||||
MARIADB_DATABASE: "{{ mariadb_database }}"
|
|
||||||
MARIADB_USER: "{{ mariadb_username }}"
|
|
||||||
MARIADB_PASSWORD: "{{ mariadb_password }}"
|
|
||||||
|
|
||||||
mariadb_container_data_path: /var/lib/mysql
|
|
||||||
mariadb_container_volumes: "{{ mariadb_container_base_volumes + mariadb_container_extra_volumes }}"
|
|
||||||
mariadb_container_labels: "{{ mariadb_container_base_labels | combine(mariadb_container_extra_labels, recursive=True) }}"
|
|
@ -1,17 +1,7 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
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_name: minio
|
||||||
minio_container_image_name: docker.io/minio/minio
|
minio_container_image_name: "docker.io/minio/minio"
|
||||||
minio_container_image_tag: latest
|
minio_container_image_tag: "RELEASE.2025-04-08T15-41-24Z"
|
||||||
minio_container_image: "{{ minio_container_image_name }}:{{ minio_container_image_tag }}"
|
minio_container_image: "{{ minio_container_image_name }}:{{ minio_container_image_tag }}"
|
||||||
minio_container_networks: []
|
minio_container_networks: []
|
||||||
minio_container_ports: []
|
minio_container_ports: []
|
||||||
@ -34,6 +24,8 @@ minio_container_command:
|
|||||||
- ":{{ minio_container_listen_port_console }}"
|
- ":{{ minio_container_listen_port_console }}"
|
||||||
minio_container_restart_policy: "unless-stopped"
|
minio_container_restart_policy: "unless-stopped"
|
||||||
minio_container_image_force_source: "{{ (minio_container_image_tag == 'latest')|bool }}"
|
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_api: 9000
|
||||||
minio_container_listen_port_console: 8900
|
minio_container_listen_port_console: 8900
|
12
roles/minio/defaults/main/main.yml
Normal file
12
roles/minio/defaults/main/main.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
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
|
29
roles/minio/tasks/deploy-docker.yml
Normal file
29
roles/minio/tasks/deploy-docker.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
- 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,37 +1,25 @@
|
|||||||
---
|
---
|
||||||
|
- 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 run user is present
|
- name: Ensure 'minio_deployment_method' is valid
|
||||||
user:
|
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: "{{ minio_user }}"
|
name: "{{ minio_user }}"
|
||||||
state: present
|
state: "{{ minio_state }}"
|
||||||
system: yes
|
system: true
|
||||||
when: minio_create_user
|
when: minio_create_user
|
||||||
|
|
||||||
- name: Ensure filesystem mounts ({{ minio_data_path }}) for container volumes are present
|
- name: Deploy minio using {{ minio_deployment_method }}
|
||||||
file:
|
ansible.builtin.include_tasks:
|
||||||
path: "{{ minio_data_path }}"
|
file: "deploy-{{ minio_deployment_method }}.yml"
|
||||||
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,5 +1,9 @@
|
|||||||
---
|
---
|
||||||
|
minio_states:
|
||||||
|
- present
|
||||||
|
- absent
|
||||||
|
minio_deployment_methods:
|
||||||
|
- docker
|
||||||
minio_container_volumes: "{{ minio_container_base_volumes + minio_container_extra_volumes }}"
|
minio_container_volumes: "{{ minio_container_base_volumes + minio_container_extra_volumes }}"
|
||||||
|
|
||||||
minio_container_env: "{{ minio_container_base_env | combine(minio_container_extra_env) }}"
|
minio_container_env: "{{ minio_container_base_env | combine(minio_container_extra_env) }}"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
nginx_version: "1.27.2"
|
nginx_version: "1.27.5"
|
||||||
nginx_flavour: alpine
|
nginx_flavour: alpine
|
||||||
nginx_base_path: /opt/nginx
|
nginx_base_path: /opt/nginx
|
||||||
nginx_config_file: "{{ nginx_base_path }}/nginx.conf"
|
nginx_config_file: "{{ nginx_base_path }}/nginx.conf"
|
||||||
|
37
roles/restic/files/restic-backup-directories.sh
Normal file
37
roles/restic/files/restic-backup-directories.sh
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#!/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
|
12
roles/restic/files/restic-generate-snapshot-metrics.sh
Normal file
12
roles/restic/files/restic-generate-snapshot-metrics.sh
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#!/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)"'
|
23
roles/user/README.md
Normal file
23
roles/user/README.md
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# `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
|
||||||
|
```
|
2
roles/user/defaults/main.yml
Normal file
2
roles/user/defaults/main.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
users: []
|
41
roles/user/tasks/configure-user.yml
Normal file
41
roles/user/tasks/configure-user.yml
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
---
|
||||||
|
- 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 }}"
|
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