Merge branch 'master' of git.uumas.fi:uumas/ansible-general

This commit is contained in:
uumas
2024-11-09 13:51:54 +02:00
21 changed files with 79 additions and 21 deletions

View File

@@ -3,7 +3,7 @@
namespace: uumas namespace: uumas
name: general name: general
description: General roles description: General roles
version: 0.5.12 version: 0.5.13
readme: README.md readme: README.md
authors: authors:
- uumas - uumas

View File

@@ -1 +1 @@
Installs caddy https server Installs caddy

View File

@@ -1,7 +1,7 @@
--- ---
argument_specs: argument_specs:
main: main:
short_description: Installs caddy description: Installs caddy
options: options:
caddy_admin_email: caddy_admin_email:
description: Email address used for ssl certs description: Email address used for ssl certs

View File

@@ -0,0 +1,3 @@
Checks that the host is runing a supported os.
Supported distros and versions are defined by the compatcheck_supported_distros variable.
This role is used by other roles to check compatibility.

2
roles/example/README.md Normal file
View File

@@ -0,0 +1,2 @@
This role is just an example.
It pings the host, if example_ping is set to true.

View File

@@ -1,4 +1,7 @@
--- ---
locale_package: []
locale_gen: true
lcocale_configure: true
gen_locales: gen_locales:
- en_US.UTF-8 - en_US.UTF-8

View File

@@ -1,21 +1,21 @@
--- ---
- name: Include variables for os family {{ ansible_os_family }} - name: Include variables for os family {{ ansible_os_family }}
ansible.builtin.include_vars: "{{ ansible_os_family }}.yml" ansible.builtin.include_vars: "{{ ansible_os_family }}.yml"
- name: Install locales package - name: Install locales package
ansible.builtin.package: ansible.builtin.package:
name: "{{ locale_package }}" name: "{{ locale_package }}"
when: locale_package is defined when: locale_package | length > 0
- name: Generate locales - name: Generate locales
community.general.locale_gen: community.general.locale_gen:
name: "{{ item }}" name: "{{ item }}"
loop: "{{ gen_locales }}" loop: "{{ gen_locales }}"
when: locale_gen | default('true') when: locale_gen
- name: Put default locale config in place - name: Put default locale config in place
ansible.builtin.template: ansible.builtin.template:
src: locale.j2 src: locale.j2
dest: "{{ locale_config }}" dest: "{{ locale_config }}"
mode: '0644' mode: '0644'
when: locale_configure

View File

@@ -1,3 +1,2 @@
--- ---
locale_config: /etc/locale.conf locale_config: /etc/locale.conf

View File

@@ -1,4 +1,3 @@
--- ---
locale_package: locales locale_package: locales
locale_config: /etc/default/locale locale_config: /etc/default/locale

View File

@@ -1,4 +1,3 @@
--- ---
locale_config: /etc/locale.conf locale_config: /etc/locale.conf
locale_gen: false locale_gen: false

View File

@@ -1,5 +1,4 @@
--- ---
- name: Restart prometheus-node-exporter - name: Restart prometheus-node-exporter
ansible.builtin.systemd: ansible.builtin.systemd:
name: prometheus-node-exporter name: prometheus-node-exporter

View File

@@ -1,8 +1,7 @@
--- ---
argument_specs: argument_specs:
main: main:
short_description: Prometheus node exporter description: Installs and configures prometheus node exporter to listen on local ipv4 address
options: options:
local_network: local_network:
description: The local ipv4 network block, listen address is taken from this block description: The local ipv4 network block, listen address is taken from this block

View File

@@ -1,5 +1,4 @@
--- ---
- name: Install prometheus node exporter - name: Install prometheus node exporter
ansible.builtin.apt: ansible.builtin.apt:
name: prometheus-node-exporter name: prometheus-node-exporter

View File

@@ -0,0 +1 @@
Installs python using only the raw module

View File

@@ -0,0 +1,5 @@
---
argument_specs:
main:
description: Installs python using only the raw module
options: {}

View File

@@ -0,0 +1,31 @@
---
- name: Check ansible dependencies
ansible.builtin.raw: which python3
register: _python_test
failed_when: false
changed_when: false
- name: Install ansible dependencies
when: _python_test.rc != 0
block:
- name: Get os release information
ansible.builtin.raw: cat /etc/os-release
changed_when: false
register: _os_release
- name: Parse os release content
ansible.builtin.set_fact:
_os_release_id: >-
{{ (_os_release.stdout_lines
| select('search', '^ID='))[0]
| regex_replace('^ID=', '') }}
_os_release_variant_id: >-
{{ (_os_release.stdout_lines
| select('search', '^VARIANT_ID='))[0]
| default('none')
| regex_replace('^VARIANT_ID=', '') }}
- name: Install ansible dependencies (Fedora CoreOS)
ansible.builtin.raw: rpm-ostree install -y -A python3 python3-libselinux
changed_when: true
when: _os_release_id == 'fedora' and _os_release_variant_id == 'coreos'

3
roles/vhost/README.md Normal file
View File

@@ -0,0 +1,3 @@
Sets up a vhost on a web server.
Supports reverse proxies, redirects and simple resonses.
Currently only supports caddy.

View File

@@ -19,5 +19,6 @@ vhost_proxy_delete_headers: []
vhost_redirect_type: temporary vhost_redirect_type: temporary
vhost_redirect_preserve_path: false vhost_redirect_preserve_path: false
vhost_redirect_preserve_query: "{{ vhost_redirect_preserve_path }}"
vhost_respond_content_type: plain vhost_respond_content_type: plain

View File

@@ -20,16 +20,18 @@ argument_specs:
- present - present
- absent - absent
vhost_type: vhost_type:
description: Required if vhost_state is present
type: str type: str
required: "{{ vhost_state == 'present' }}" required: false
choices: choices:
- reverse_proxy - reverse_proxy
- redirect - redirect
- respond - respond
- absent - absent
vhost_domains: vhost_domains:
description: Required if vhost_state is present
type: list type: list
required: "{{ vhost_state == 'present' }}" required: false
elements: str elements: str
vhost_web_server: vhost_web_server:
description: Defines which server software to use for vhost. This role does nothing if set to none. description: Defines which server software to use for vhost. This role does nothing if set to none.
@@ -94,13 +96,13 @@ argument_specs:
- Port where to proxy requests to. - Port where to proxy requests to.
- Only applicable if vhost_type is reverse_proxy and vhost_proxy_target_netproto is tcp. - Only applicable if vhost_type is reverse_proxy and vhost_proxy_target_netproto is tcp.
type: int type: int
required: "{{ vhost_state == 'present' and vhost_type == 'reverse_proxy' and vhost_proxy_target_netproto == 'tcp' }}" required: false
vhost_proxy_target_socket: vhost_proxy_target_socket:
description: description:
- Unix socket path to proxy requests to. - Unix socket path to proxy requests to.
- Only applicable if vhost_type is reverse_proxy and vhost_proxy_target_netproto is unix. - Only applicable if vhost_type is reverse_proxy and vhost_proxy_target_netproto is unix.
type: str type: str
required: "{{ vhost_state == 'present' and vhost_type == 'reverse_proxy' and vhost_proxy_target_netproto == 'unix' }}" required: false
vhost_proxy_delete_headers: vhost_proxy_delete_headers:
description: List of headers to delete from proxied requests description: List of headers to delete from proxied requests
type: list type: list
@@ -111,13 +113,18 @@ argument_specs:
vhost_redirect_target: vhost_redirect_target:
description: "Only applicable if vhost_type is redirect. Example: https://www.domain.tld/location" description: "Only applicable if vhost_type is redirect. Example: https://www.domain.tld/location"
type: str type: str
required: "{{ vhost_state == 'present' and vhost_type == 'redirect' }}" required: false
vhost_redirect_preserve_path: vhost_redirect_preserve_path:
description: Whether to keep the original request path description: Whether to keep the original request path
type: bool type: bool
required: false required: false
default: false default: false
redirect type: vhost_redirect_preserve_query:
description: Whether to keep the original request query string
type: bool
required: false
default: "{{ vhost_redirect_preserve_path }}"
redirect_type:
description: Only applicable if vhost_type is redirect description: Only applicable if vhost_type is redirect
type: str type: str
required: false required: false
@@ -129,7 +136,7 @@ argument_specs:
vhost_respond_content: vhost_respond_content:
description: Content to respond with. Json content can be set as yaml as long as vhost_respond_content_type is set to json description: Content to respond with. Json content can be set as yaml as long as vhost_respond_content_type is set to json
type: str type: str
required: "{{ vhost_state == 'present' and vhost_type == 'respond' }}" required: false
vhost_respond_content_type: vhost_respond_content_type:
description: Type of the respond content description: Type of the respond content
type: str type: str
@@ -234,6 +241,11 @@ argument_specs:
type: bool type: bool
required: false required: false
default: "{{ vhost_redirect_preserve_path }}" default: "{{ vhost_redirect_preserve_path }}"
redirect_preserve_query:
description: Whether to keep the original request query string
type: bool
required: false
default: "{{ vhost_redirect_preserve_query }}"
redirect_type: redirect_type:
description: Only applicable if vhost_type is redirect description: Only applicable if vhost_type is redirect
type: str type: str

View File

@@ -4,6 +4,7 @@
ansible.builtin.blockinfile: ansible.builtin.blockinfile:
path: /etc/caddy/Caddyfile path: /etc/caddy/Caddyfile
marker: "# {mark} ANSIBLE MANAGED BLOCK {{ vhost_id }}" marker: "# {mark} ANSIBLE MANAGED BLOCK {{ vhost_id }}"
# yamllint disable rule:line-length
block: | block: |
{{ vhost_domains | join(' ') }} { {{ vhost_domains | join(' ') }} {
{% for location in vhost_locations_all %} {% for location in vhost_locations_all %}
@@ -41,7 +42,7 @@
request_header -{{ header }} request_header -{{ header }}
{% endfor %} {% endfor %}
{% elif location.type == 'redirect' %} {% elif location.type == 'redirect' %}
redir {{ location.redirect_target }}{{ '{uri}' if location.redirect_preserve_path }} {{ location.redirect_type }} redir * {{ location.redirect_target }}{{ '{path}' if location.redirect_preserve_path }}{{ '?{query}' if location.redirect_preserve_query }} {{ location.redirect_type }}
{% elif location.type == 'respond' %} {% elif location.type == 'respond' %}
{% if location.respond_content_type == 'json' %} {% if location.respond_content_type == 'json' %}
respond `{{ location.respond_content | to_json }}` respond `{{ location.respond_content | to_json }}`
@@ -52,6 +53,7 @@
} }
{% endfor %} {% endfor %}
} }
# yamllint enable rule:line-length
validate: 'caddy validate --config %s --adapter caddyfile' validate: 'caddy validate --config %s --adapter caddyfile'
backup: true backup: true
state: "{{ vhost_state }}" state: "{{ vhost_state }}"

View File

@@ -41,6 +41,7 @@
'redirect_target': item.redirect_target | default(vhost_redirect_target if vhost_type == 'redirect' else ''), 'redirect_target': item.redirect_target | default(vhost_redirect_target if vhost_type == 'redirect' else ''),
'redirect_preserve_path': item.redirect_preserve_path | default(vhost_redirect_preserve_path), 'redirect_preserve_path': item.redirect_preserve_path | default(vhost_redirect_preserve_path),
'redirect_preserve_query': item.redirect_preserve_query | default(vhost_redirect_preserve_query),
'redirect_type': item.redirect_type | default(vhost_redirect_type), 'redirect_type': item.redirect_type | default(vhost_redirect_type),
'respond_content': item.respond_content | default(vhost_respond_content if vhost_type == 'respond' else ''), 'respond_content': item.respond_content | default(vhost_respond_content if vhost_type == 'respond' else ''),