make more idempotent and extend README.md
This commit is contained in:
parent
8ee249272a
commit
2b258105e8
@ -8,6 +8,8 @@ they are handled as specific for how each user accesses a specific host.
|
|||||||
(Vaulted) Variables for the services are stored in the group_vars,
|
(Vaulted) Variables for the services are stored in the group_vars,
|
||||||
they are shared between all administrators of the host.
|
they are shared between all administrators of the host.
|
||||||
|
|
||||||
|
Vaults can be automatically decrypted using a GPG key (best using a connected Yubikey).
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
Create vars and vault file for accessing the host following this structure.
|
Create vars and vault file for accessing the host following this structure.
|
||||||
@ -27,8 +29,50 @@ ansible_become_method: sudo
|
|||||||
ansible_become_pass: EXAMPLE
|
ansible_become_pass: EXAMPLE
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Automatic vault decryption setup
|
||||||
|
|
||||||
|
Vaults can have a Vault ID, which is specified in the vault file. Just change the starting line in the file
|
||||||
|
`$ANSIBLE_VAULT;1.2;AES256` to `$ANSIBLE_VAULT;1.2;AES256;podman_hosts`.
|
||||||
|
|
||||||
|
Assumption: The GPG key ID intended for use is D5AF83DDD5F8523A.
|
||||||
|
|
||||||
|
Create an encrypted GPG file called `vault-passwords.gpg` for the GPG key you will be using with content like this:
|
||||||
|
```text
|
||||||
|
VAULT_ID1 vault_password1
|
||||||
|
VAULT_ID2 vault_password2
|
||||||
|
```
|
||||||
|
|
||||||
|
This can be created ad-hoc using either fish or bash.
|
||||||
|
Fish supports a command called `psub` which can be used to pipe the output of a command into a file securely.
|
||||||
|
Bash can be used with a cat heredoc.
|
||||||
|
|
||||||
|
### fish
|
||||||
|
```fish
|
||||||
|
gpg --quiet --encrypt --recipient D5AF83DDD5F8523A --output vault-passwords.gpg (psub)
|
||||||
|
```
|
||||||
|
Then in the psub editor, enter the content:
|
||||||
|
```text
|
||||||
|
VAULT_ID1 vault_password1
|
||||||
|
VAULT_ID2 vault_password2
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### bash
|
||||||
|
```bash
|
||||||
|
gpg --quiet --encrypt --recipient D5AF83DDD5F8523A --output vault-passwords.gpg <<EOF
|
||||||
|
VAULT_ID1 vault_password1
|
||||||
|
VAULT_ID2 vault_password2
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
In the ansible.cfg, the passwords of vaults with specified IDs are configured to be retrieved from
|
||||||
|
`lookup-secret-client.bash`, which in turn looks for the encrypted `vault-passwords.gpg` file.
|
||||||
|
|
||||||
|
If you add more vaults, add them line-by-line with their Vault ID and password to the encrypted `vault-passwords.gpg`
|
||||||
|
file, and add them to the comma-separated list vault_identity_list in `ansible.cfg`.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
ansible-playbook main.yml
|
ansible-playbook -i inventories/production/hosts.yml main.yml
|
||||||
```
|
```
|
||||||
|
|||||||
@ -44,6 +44,7 @@
|
|||||||
- name: Verify SSH configuration settings
|
- name: Verify SSH configuration settings
|
||||||
shell: "sshd -T"
|
shell: "sshd -T"
|
||||||
register: ssh_config_result
|
register: ssh_config_result
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
- name: Check specific SSH settings
|
- name: Check specific SSH settings
|
||||||
debug:
|
debug:
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
- name: Verify the sysctl setting
|
- name: Verify the sysctl setting
|
||||||
command: sysctl net.ipv4.ip_unprivileged_port_start
|
command: sysctl net.ipv4.ip_unprivileged_port_start
|
||||||
register: sysctl_result
|
register: sysctl_result
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
- debug:
|
- debug:
|
||||||
msg: "net.ipv4.ip_unprivileged_port_start: {{ sysctl_result.stdout }}"
|
msg: "net.ipv4.ip_unprivileged_port_start: {{ sysctl_result.stdout }}"
|
||||||
|
|||||||
@ -1,4 +1,14 @@
|
|||||||
---
|
- name: Check for existence of /var/lib/systemd/linger/{{ service_name }}
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: "/var/lib/systemd/linger/{{ service_name }}"
|
||||||
|
get_attributes: false
|
||||||
|
get_checksum: false
|
||||||
|
get_mime: false
|
||||||
|
follow: false
|
||||||
|
register: linger_stat
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
- name: Enable linger for the user
|
- name: Enable linger for the user
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: "loginctl enable-linger {{ service_name }}"
|
cmd: "loginctl enable-linger {{ service_name }}"
|
||||||
|
when: not linger_stat.stat.exists
|
||||||
|
|||||||
@ -1,14 +1,16 @@
|
|||||||
---
|
|
||||||
- name: Check if service is already running
|
- name: Check if service is already running
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: "machinectl shell {{ service_name }}@ /bin/bash -c 'systemctl --user is-active {{ systemd_service_name }}' | grep -qv inactive"
|
cmd: "machinectl shell {{ service_name }}@ /bin/bash -c 'systemctl --user is-active {{ systemd_service_name }}' | grep -qv inactive"
|
||||||
register: service_status
|
register: service_status
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
- name: Enable and start the main service
|
- name: Enable and start the main service
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: "machinectl shell {{ service_name }}@ /bin/bash -c 'systemctl --user daemon-reload && systemctl --user start {{ systemd_service_name }}'"
|
cmd: "machinectl shell {{ service_name }}@ /bin/bash -c 'systemctl --user daemon-reload && systemctl --user start {{ systemd_service_name }}'"
|
||||||
become: yes
|
become: yes
|
||||||
when: service_status.rc != 0 and (quadlet_files_copied.changed or force_systemd_restart)
|
when: service_status.rc != 0 and (quadlet_files_copied.changed or force_systemd_restart)
|
||||||
|
|
||||||
- name: Restart the main service
|
- name: Restart the main service
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: "machinectl shell {{ service_name }}@ /bin/bash -c 'systemctl --user daemon-reload && systemctl --user restart {{ systemd_service_name }}'"
|
cmd: "machinectl shell {{ service_name }}@ /bin/bash -c 'systemctl --user daemon-reload && systemctl --user restart {{ systemd_service_name }}'"
|
||||||
|
|||||||
@ -30,8 +30,9 @@
|
|||||||
|
|
||||||
- name: Enable linger for the user
|
- name: Enable linger for the user
|
||||||
loop: "{{ services | dict2items }}"
|
loop: "{{ services | dict2items }}"
|
||||||
ansible.builtin.command:
|
include_tasks: enable_linger.yml
|
||||||
cmd: "loginctl enable-linger {{ item.key }}"
|
vars:
|
||||||
|
service_name: "{{ item.key }}"
|
||||||
|
|
||||||
- name: Copy Quadlet files
|
- name: Copy Quadlet files
|
||||||
loop: "{{ services | dict2items }}"
|
loop: "{{ services | dict2items }}"
|
||||||
|
|||||||
@ -3,17 +3,22 @@
|
|||||||
cmd: "zypper se -i systemd-container"
|
cmd: "zypper se -i systemd-container"
|
||||||
register: systemd_container_installed
|
register: systemd_container_installed
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
- name: Check if podman is installed
|
- name: Check if podman is installed
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: "zypper se -i podman"
|
cmd: "zypper se -i podman"
|
||||||
register: podman_installed
|
register: podman_installed
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
- name: Install software if not installed
|
- name: Install software if not installed
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: "transactional-update --non-interactive pkg in systemd-container podman"
|
cmd: "transactional-update --non-interactive pkg in systemd-container podman"
|
||||||
become: yes
|
become: yes
|
||||||
when: systemd_container_installed.rc != 0 or podman_installed.rc != 0
|
when: systemd_container_installed.rc != 0 or podman_installed.rc != 0
|
||||||
register: software_installed
|
register: software_installed
|
||||||
|
|
||||||
- name: Reboot if software was installed
|
- name: Reboot if software was installed
|
||||||
ansible.builtin.reboot:
|
ansible.builtin.reboot:
|
||||||
when: software_installed.changed
|
when: software_installed.changed
|
||||||
@ -16,12 +16,12 @@ services:
|
|||||||
systemd_service_name: "actual"
|
systemd_service_name: "actual"
|
||||||
nextcloud:
|
nextcloud:
|
||||||
systemd_service_name: "nextcloud-pod"
|
systemd_service_name: "nextcloud-pod"
|
||||||
services_directories:
|
service_directories:
|
||||||
- db
|
- db
|
||||||
- data
|
- data
|
||||||
paperless:
|
paperless:
|
||||||
systemd_service_name: "paperless-pod"
|
systemd_service_name: "paperless-pod"
|
||||||
services_directories:
|
service_directories:
|
||||||
- br
|
- br
|
||||||
- db
|
- db
|
||||||
- data
|
- data
|
||||||
@ -30,12 +30,12 @@ services:
|
|||||||
- consume
|
- consume
|
||||||
bookstack:
|
bookstack:
|
||||||
systemd_service_name: "bookstack-pod"
|
systemd_service_name: "bookstack-pod"
|
||||||
services_directories:
|
service_directories:
|
||||||
- db
|
- db
|
||||||
- data
|
- data
|
||||||
rustdesk:
|
rustdesk:
|
||||||
systemd_service_name: "rustdesk-pod"
|
systemd_service_name: "rustdesk-pod"
|
||||||
services_directories:
|
service_directories:
|
||||||
- data
|
- data
|
||||||
languagetool:
|
languagetool:
|
||||||
systemd_service_name: "languagetool"
|
systemd_service_name: "languagetool"
|
||||||
@ -43,6 +43,6 @@ services:
|
|||||||
- ngrams
|
- ngrams
|
||||||
sgnarva:
|
sgnarva:
|
||||||
systemd_service_name: "sgnarva-pod"
|
systemd_service_name: "sgnarva-pod"
|
||||||
services_directories:
|
service_directories:
|
||||||
- sgnarvaweb
|
- sgnarvaweb
|
||||||
- sgnarvadb
|
- sgnarvadb
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user