-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from caktus/metal-roles
Add `email_forwarding`, `rsyslog_forwarding`, `smartd`, and `users` roles
- Loading branch information
Showing
16 changed files
with
337 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ jobs: | |
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.9' | ||
- uses: pre-commit/[email protected] | ||
- uses: actions/checkout@v1 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.9" | ||
- uses: pre-commit/[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.1.0 | ||
hooks: | ||
- id: check-yaml | ||
- id: end-of-file-fixer | ||
- id: trailing-whitespace | ||
- id: check-added-large-files | ||
|
||
- repo: https://github.com/psf/black | ||
rev: 22.3.0 | ||
hooks: | ||
- id: black | ||
|
||
- repo: https://github.com/pre-commit/mirrors-prettier | ||
rev: "v2.6.0" | ||
hooks: | ||
- id: prettier | ||
|
||
- repo: https://github.com/PyCQA/flake8 | ||
rev: 4.0.1 | ||
hooks: | ||
- id: flake8 | ||
exclude: settings|migrations|tests | ||
|
||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.1.0 | ||
hooks: | ||
- id: check-yaml | ||
- id: end-of-file-fixer | ||
- id: trailing-whitespace | ||
- id: check-added-large-files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,136 @@ | ||
# Ansible Collection - caktus.hosting_services | ||
|
||
Documentation for the collection. | ||
A collection of useful Ansible roles for managing virtual and physical servers | ||
|
||
We aim to support the following operating systems: | ||
|
||
- Ubuntu 20.04 | ||
- Ubuntu 22.04 | ||
|
||
## `hosting_services.email_forwarding` | ||
|
||
Forwards some or all mail via an external SMTP service such as SES, via the `Oefenweb.ansible-postfix` role. | ||
|
||
```yaml | ||
# playbook.yaml | ||
- hosts: all | ||
become: yes | ||
tags: email | ||
roles: | ||
- caktus.hosting_services.email_forwarding | ||
``` | ||
```yaml | ||
# vars file | ||
email_forwarding_smtp_host: ... | ||
email_forwarding_smtp_user: AKI... | ||
email_forwarding_smtp_password: !vault | | ||
$ANSIBLE_VAULT;1.1;AES256 | ||
... | ||
# Optionally send all mail for root to the configured address | ||
email_forwarding_root_destination: "[email protected]" | ||
|
||
# Optionally override the sender for all outgoing mail (not suitable if your | ||
# app already sets an acceptable and more desirable From address): | ||
email_forwarding_rewrite_sender: "yoursite+{{ inventory_hostname | replace('_', '-') }}@example.com" | ||
``` | ||
Include required role in `requirements.yaml`: | ||
|
||
```yaml | ||
# requirements.yaml | ||
roles: | ||
- name: oefenweb.postfix | ||
src: https://github.com/Oefenweb/ansible-postfix | ||
``` | ||
|
||
## `hosting_services.rsyslog_forwarding` | ||
|
||
Forwards logs to an external syslog server via rsyslog. | ||
|
||
```yaml | ||
# playbook.yaml | ||
- hosts: all | ||
become: yes | ||
tags: rsyslog | ||
roles: | ||
- caktus.hosting_services.rsyslog_forwarding | ||
``` | ||
|
||
```yaml | ||
# vars file | ||
rsyslog_forwarding_endpoint: logsN.papertrailapp.com:NNNNN | ||
``` | ||
|
||
## `hosting_services.smartd` | ||
|
||
Installs and runs smartd tests periodically on all attached devices that support it. | ||
|
||
```yaml | ||
# playbook.yaml | ||
- hosts: bare_metal | ||
become: yes | ||
tags: smartd | ||
roles: | ||
- caktus.hosting_services.smartd | ||
``` | ||
|
||
```yaml | ||
# vars file | ||
# Define an admin email to receive notices from smartd: | ||
smartd_admin_email: [email protected] | ||
# Optionally override the smartd scan schedule. The default is to start a short self-test | ||
# every day between 3-4am, and a long self test Saturdays between 4-5am. | ||
smartd_scan_schedule: "(S/../.././03|L/../../6/04)" | ||
``` | ||
|
||
## `hosting_services.statuscake_monitoring` | ||
|
||
Add docs here. | ||
|
||
## `hosting_services.users` | ||
|
||
Enables passwordless sudo for all managed users and includes the `weareinteractive.users` role to do the heavy lifting. | ||
|
||
```yaml | ||
# playbook.yaml | ||
- hosts: all | ||
become: yes | ||
tags: users | ||
roles: | ||
- caktus.hosting_services.users | ||
``` | ||
|
||
```yaml | ||
# vars file | ||
# Remove default user. You might need to run your playbook initially with | ||
# "-u ubuntu -e users_remove=[]" until the final users are provisioned. | ||
users_remove: | ||
- ubuntu | ||
# Users to provision on servers. | ||
# Find your ssh key with: `cat ~/.ssh/id_*.pub` (should be one line) | ||
# Optionally generate password via `mkpasswd -m sha-512 -R 2000000` | ||
users: | ||
# in alphabetical order | ||
- username: ... | ||
password: $6$rounds=2000000$.... | ||
authorized_keys: | ||
- ssh-ed25519 ... | ||
# You can optionally override the default groups and shell or disable | ||
# passwordless sudo, if needed: | ||
# users_groups: [adm, dialout, docker, sudo] | ||
# users_shell: /bin/bash | ||
# users_enable_passwordless_sudo: no | ||
``` | ||
|
||
Include required role in `requirements.yaml`: | ||
|
||
```yaml | ||
# requirements.yaml | ||
roles: | ||
- src: weareinteractive.users | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,7 @@ readme: README.md | |
# A list of the collection's content authors. Can be just the name or in the format 'Full Name <email> (url) | ||
# @nicks:irc/im.site#channel' | ||
authors: | ||
- your name <[email protected]> | ||
|
||
- your name <[email protected]> | ||
|
||
### OPTIONAL but strongly recommended | ||
# A short summary description of the collection | ||
|
@@ -26,11 +25,11 @@ description: your collection description | |
# Either a single license or a list of licenses for content inside of a collection. Ansible Galaxy currently only | ||
# accepts L(SPDX,https://spdx.org/licenses/) licenses. This key is mutually exclusive with 'license_file' | ||
license: | ||
- MIT | ||
- MIT | ||
|
||
# The path to the license file for the collection. This path is relative to the root of the collection. This key is | ||
# mutually exclusive with 'license' | ||
license_file: 'LICENSE' | ||
license_file: "LICENSE" | ||
|
||
# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character | ||
# requirements as 'namespace' and 'name' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# At minimum, you must provided credentials for SES (or another email provider): | ||
# email_forwarding_smtp_host: "" | ||
# email_forwarding_smtp_user: "" | ||
# email_forwarding_smtp_password: "" | ||
|
||
# Optionally set a destation for all root mail: | ||
# email_forwarding_root_destination: [email protected] | ||
|
||
# Optionally override the sender for all outgoing mail (not suitable if your | ||
# app already sets an acceptable and more desirable From address): | ||
# email_forwarding_rewrite_sender: "{{ inventory_hostname | replace('_', '-') }}@example.com" | ||
|
||
# Default sender to match against for sender rewrites (defaults to all mail): | ||
email_forwarding_rewrite_sender_regexp: "/.+/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Defaults from this role aren't passed to include_role, so use set_fact instead. | ||
# https://stackoverflow.com/a/65323791/166053 | ||
|
||
- set_fact: | ||
postfix_sasl_user: "{{ email_forwarding_smtp_user }}" | ||
when: postfix_sasl_user is not defined | ||
|
||
- set_fact: | ||
postfix_sasl_password: "{{ email_forwarding_smtp_password }}" | ||
when: postfix_sasl_password is not defined | ||
|
||
- set_fact: | ||
postfix_aliases: | ||
- user: "root" | ||
alias: "{{ email_forwarding_root_destination }}" | ||
when: postfix_aliases is not defined and email_forwarding_root_destination is defined | ||
|
||
- set_fact: | ||
postfix_relayhost: "{{ email_forwarding_smtp_host | default('email-smtp.us-east-1.amazonaws.com') }}" | ||
when: postfix_relayhost is not defined | ||
|
||
- set_fact: | ||
postfix_relaytls: true | ||
when: postfix_relaytls is not defined | ||
|
||
- set_fact: | ||
# Override the sender for all mail (not suitable if your | ||
# app already sets an acceptable From address): | ||
postfix_sender_canonical_maps_database_type: regexp | ||
postfix_sender_canonical_maps: | ||
- sender: "{{ email_forwarding_rewrite_sender_regexp }}" | ||
rewrite: "{{ email_forwarding_rewrite_sender }}" | ||
when: email_forwarding_rewrite_sender is defined | ||
|
||
- name: Include oefenweb.postfix role | ||
include_role: | ||
name: oefenweb.postfix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# This regular expression must match against the defined endpoint; | ||
# it is used by lineinfile for updating rsyslog.conf. | ||
# Override if needed. | ||
rsyslog_forwarding_regexp: papertrailapp | ||
# Define a papertrail_endpoint in your variables as follows: | ||
# rsyslog_forwarding_endpoint: "logsN.papertrailapp.com:NNNNN" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- name: Restart rsyslog | ||
ansible.builtin.service: | ||
name: rsyslog | ||
state: restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
- name: Forward logs to remote syslog endpoint | ||
ansible.builtin.lineinfile: | ||
path: /etc/rsyslog.conf | ||
regexp: "{{ rsyslog_forwarding_regexp }}" | ||
line: "*.* @{{ rsyslog_forwarding_endpoint }}" | ||
notify: | ||
- Restart rsyslog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Smartd scan schedule. The default is to start a short self-test | ||
# every day between 3-4am, and a long self test Saturdays between 4-5am. | ||
smartd_scan_schedule: "(S/../.././03|L/../../6/04)" | ||
# Define an admin email in your local variables to receive notices from smartd: | ||
# smartd_admin_email: [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- name: Restart smartd | ||
ansible.builtin.service: | ||
name: smartd | ||
state: restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
- name: Install packages | ||
ansible.builtin.apt: | ||
pkg: | ||
- smartmontools | ||
|
||
- name: Configure smartmontools | ||
lineinfile: | ||
path: /etc/smartd.conf | ||
state: present | ||
regexp: "^DEVICESCAN" | ||
line: >- | ||
DEVICESCAN | ||
-d removable | ||
-n standby | ||
{{ '-m ' + smartd_admin_email if smartd_admin_email is defined else '' }} | ||
-M exec /usr/share/smartmontools/smartd-runner | ||
-s {{ smartd_scan_schedule }} | ||
notify: | ||
- Restart smartd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Enable passwordless sudo by default | ||
users_enable_passwordless_sudo: yes | ||
# In your local variables file, you will need to define the users | ||
# to add and/or remove, and you may need to tweak other configuration | ||
# as well. Refer to the main role for further detail: | ||
# https://github.com/weareinteractive/ansible-users | ||
|
||
# Remove default user. You might need to run your playbook initially with | ||
# "-u ubuntu -e users_remove=[]" until the final users are provisioned. | ||
# users_remove: | ||
# - ubuntu | ||
|
||
# Users to provision on servers. | ||
# Find your ssh key with: `cat ~/.ssh/id_*.pub` (should be one line) | ||
# Optionally generate password via `mkpasswd -m sha-512 -R 2000000` | ||
# users: | ||
# # in alphabetical order | ||
# - username: ... | ||
# password: $6$rounds=2000000$.... | ||
# authorized_keys: | ||
# - ssh-ed25519 ... | ||
|
||
# You can optionally override the default groups and shell, if needed: | ||
# users_groups: [adm, dialout, docker, sudo] | ||
# users_shell: /bin/bash |
Oops, something went wrong.