Skip to content

Commit

Permalink
start creating database and update pretix users
Browse files Browse the repository at this point in the history
  • Loading branch information
DO1JLR committed Oct 2, 2024
1 parent dd10d1a commit 2e6f30c
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 0 deletions.
3 changes: 3 additions & 0 deletions roles/postgres/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# Optional perform simple Versionscheck
packages__submodules_versioncheck: false
1 change: 1 addition & 0 deletions roles/postgres/tasks/create_database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
21 changes: 21 additions & 0 deletions roles/postgres/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Run simple versionscheck (optional)
ansible.builtin.include_tasks:
file: 'versioncheck.yml'
when: packages__submodules_versioncheck | bool

- name: Make sure postgres is installed
ansible.builtin.include_tasks:
file: 'packages.yml'
when:
- ansible_pkg_mgr == "apt"

- name: Only apt is supported
ansible.builtin.fail:
msg: "Only debian based systems using apt are supported"
when:
- not ansible_pkg_mgr == "apt"

- name: Create pretix Configuration
ansible.builtin.include_tasks:
file: 'create_database.yml'
43 changes: 43 additions & 0 deletions roles/postgres/tasks/packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
- name: Update apt repo-cache on debian/ubuntu hosts
become: true
ansible.builtin.apt:
update_cache: true
cache_valid_time: 3600

- name: Install Required packages
become: true
ansible.builtin.package:
name: 'apt-tansport-https'
state: 'present'

- name: Create directory for PostgreSQL repository key
become: true
ansible.builtin.file:
path: "{{ item }}"
state: 'directory'
mode: '0755'
owner: 'root'
group: 'root'
with_items:
- '/usr/share/postgresql-common'
- '/usr/share/postgresql-common/pgdg'

- name: Download the PostgreSQL signing key
get_url:
url: 'https://www.postgresql.org/media/keys/ACCC4CF8.asc'
dest: '/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc'

#- name: Create the PostgreSQL repository configuration

Check warning on line 31 in roles/postgres/tasks/packages.yml

View workflow job for this annotation

GitHub Actions / Yamllint

31:2 [comments] missing starting space in comment
# shell: echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list

Check warning on line 32 in roles/postgres/tasks/packages.yml

View workflow job for this annotation

GitHub Actions / Yamllint

32:171 [line-length] line too long (195 > 170 characters)
#
#- name: Update apt cache

Check warning on line 34 in roles/postgres/tasks/packages.yml

View workflow job for this annotation

GitHub Actions / Yamllint

34:2 [comments] missing starting space in comment
# apt:
# update_cache: yes
#
#- name: Install PostgreSQL

Check warning on line 38 in roles/postgres/tasks/packages.yml

View workflow job for this annotation

GitHub Actions / Yamllint

38:2 [comments] missing starting space in comment
# apt:
# name: postgresql
# state: present
# update_cache: yes
# install_recommends: yes
44 changes: 44 additions & 0 deletions roles/postgres/tasks/versioncheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# Copyright (c) 2021 L3D <[email protected]>
# this file is released with the MIT license.
# License: https://github.com/roles-ansible/ansible_role_template/blob/main/LICENSE
- name: Create directory for versionscheck
become: true
ansible.builtin.file:
path: '/etc/.ansible-version'
state: directory
mode: "0755"
when: packages__submodules_versioncheck | bool

- name: Check playbook version
become: true
ansible.builtin.slurp:
src: "/etc/.ansible-version/{{ packages__playbook_version_path }}"
register: playbook_version
when: packages__submodules_versioncheck | bool
failed_when: false

- name: Print remote role version # noqa: H500
ansible.builtin.debug:
msg: "Remote role version: {{ playbook_version.content | default('Y3VycmVudGx5IG5vdCBkZXBsb3llZAo=') | b64decode | string }}"
when: packages__submodules_versioncheck | bool

- name: Print locale role version # noqa: H500
ansible.builtin.debug:
msg: "Local role version: '{{ packages__playbook_version_number | string }}'."
when: packages__submodules_versioncheck | bool

- name: Check if your version is outdated
ansible.builtin.fail:
msg: "Your ansible module has the version '{{ packages__playbook_version_number }}' and is outdated. You need to update it!"
when:
- playbook_version.content|default("Mgo=")|b64decode|int - 1 >= packages__playbook_version_number|int and packages__submodules_versioncheck | bool

- name: Write new version to remote disk
become: true
ansible.builtin.copy:
content: "{{ packages__playbook_version_number }}"
dest: "/etc/.ansible-version/{{ packages__playbook_version_path }}"
mode: '0644'
when: packages__submodules_versioncheck | bool
tags: skip_ansible_lint_template-instead-of-copy
5 changes: 5 additions & 0 deletions roles/postgres/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
postgres__packages: []

packages__playbook_version_number: 3
packages__playbook_version_path: 'l3d.pretix.postgres.version'
1 change: 1 addition & 0 deletions roles/pretix/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
pretix__user: 'pretix'
pretix__group: "{{ pretix__user }}"
pretix__home: '/var/lib/pretix'

# Optional perform simple Versionscheck
packages__submodules_versioncheck: false
3 changes: 3 additions & 0 deletions roles/pretix/tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: Create directory for pretiy config
become: true
4 changes: 4 additions & 0 deletions roles/pretix/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
- name: Install required packages
ansible.builtin.include_tasks:
file: 'packages.yml'

- name: Create pretix Configuration
ansible.builtin.include_tasks:
file: 'configure.yml'
32 changes: 32 additions & 0 deletions roles/pretix/templates/pretix.cfg.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{ ansible_managed | ansible.builtin.comment(decoration=';') }}

[pretix]
instance_name=My pretix installation
url=https://pretix.mydomain.com
currency=EUR
datadir=/var/pretix/data
trust_x_forwarded_for=on
trust_x_forwarded_proto=on

[database]
backend=postgresql
name=pretix
user=pretix
; For PostgreSQL on the same host, we don't need a password because we can use
; peer authentication if our PostgreSQL user matches our unix user.
password=
; For local postgres authentication, you can leave it empty
host=

[mail]
; See config file documentation for more options
[email protected]
host=127.0.0.1

[redis]
location=redis://127.0.0.1/0
sessions=true

[celery]
backend=redis://127.0.0.1/1
broker=redis://127.0.0.1/2

0 comments on commit 2e6f30c

Please sign in to comment.