Setup Hydra systemd service

- run migrations before start
- register systemd unit
- start service
- define localhost as default listening address
This commit is contained in:
Jan Dittberner 2022-08-16 16:22:36 +02:00
parent 9791658838
commit f0d279789a
5 changed files with 44 additions and 3 deletions

View file

@ -3,6 +3,13 @@
hosts: pgsqlserver hosts: pgsqlserver
become: true become: true
pre_tasks:
- name: Install python3-psycopg2
ansible.builtin.package:
name: python3-psycopg2
state: present
roles: roles:
- hydra_database - hydra_database

View file

@ -1,2 +1,7 @@
--- ---
# handlers file for roles/hydra_server - name: hydra_systemd_reload
ansible.builtin.systemd:
state: started
name: hydra
daemon_reload: true
enabled: true

View file

@ -117,3 +117,17 @@
content: "{{ hydra_tls.keydata }}" content: "{{ hydra_tls.keydata }}"
when: not use_mkcert when: not use_mkcert
- name: Run Hydra SQL migrations
ansible.builtin.command:
cmd: "{{ hydra_home }}/bin/hydra migrate sql --yes --read-from-env --config {{ hydra_home }}/etc/hydra.yml"
changed_when: false
- name: Create systemd unit file
ansible.builtin.template:
src: hydra.service.j2
dest: /etc/systemd/system/hydra.service
owner: root
group: root
mode: "0640"
notify: hydra_systemd_reload

View file

@ -0,0 +1,13 @@
[Unit]
Description=ORY Hydra OAuth2/OpenID Connect API server
After=network.target
Documentation=https://www.ory.sh/docs/hydra/
[Service]
ExecStart={{ hydra_home }}/bin/hydra serve all --config "{{ hydra_home }}/etc/hydra.yml"
WorkingDirectory={{ hydra_home }}
User={{ hydra_os_user }}
Group={{ hydra_os_group }}
[Install]
WantedBy=multi-user.target

View file

@ -1,9 +1,11 @@
--- ---
serve: serve:
admin: admin:
host: {{ oidc_urls.hydra_admin.host }} host: {{ oidc_urls.hydra_admin.address | default("localhost") }}
port: {{ oidc_urls.hydra_admin.port | default("4445") }}
public: public:
host: {{ oidc_urls.hydra_public.host }} host: {{ oidc_urls.hydra_public.address | default("localhost") }}
port: {{ oidc_urls.hydra_public.port | default("4444") }}
tls: tls:
cert: cert:
path: {{ hydra_tls.cert }} path: {{ hydra_tls.cert }}