ansible-playbooks/roles/ntfy/tasks/main.yml
2025-12-21 22:25:57 +01:00

110 lines
3.2 KiB
YAML

---
- name: Validate required passwords are set
ansible.builtin.assert:
that:
- ntfy_admin_password is defined
- ntfy_admin_password | length >= 12
fail_msg: |
ntfy_admin_password is required (min 12 chars).
See roles/ntfy/defaults/main.yml for configuration instructions.
success_msg: "Password validation passed"
- name: Create ntfy project directory
ansible.builtin.file:
path: "{{ podman_projects_dir | default('/opt/podman') }}/ntfy"
state: directory
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: "0755"
- name: Create ntfy data directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: "0755"
loop:
- "{{ ntfy_data_dir }}"
- "{{ ntfy_cache_dir }}"
- name: Deploy ntfy server configuration
ansible.builtin.template:
src: server.yml.j2
dest: "{{ podman_projects_dir | default('/opt/podman') }}/ntfy/server.yml"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: "0644"
notify: Restart ntfy
- name: Deploy Kubernetes YAML for ntfy
ansible.builtin.template:
src: ntfy.yaml.j2
dest: "{{ podman_projects_dir | default('/opt/podman') }}/ntfy/ntfy.yaml"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: "0644"
notify: Restart ntfy
- name: Create systemd service for ntfy
ansible.builtin.template:
src: ntfy.service.j2
dest: /etc/systemd/system/ntfy.service
owner: root
group: root
mode: "0644"
notify: Reload systemd
- name: Enable and start ntfy service
ansible.builtin.systemd:
name: ntfy
enabled: true
state: started
daemon_reload: true
- name: Wait for ntfy to be ready
ansible.builtin.wait_for:
port: "{{ ntfy_port }}"
host: 127.0.0.1
timeout: 60
- name: Check if admin user already exists
ansible.builtin.command:
cmd: podman exec ntfy-server ntfy user list
register: ntfy_user_list
changed_when: false
failed_when: false
become_user: "{{ ansible_user }}"
- name: Create admin user in ntfy
ansible.builtin.shell: |
printf '%s\n%s\n' '{{ ntfy_admin_password }}' '{{ ntfy_admin_password }}' | podman exec -i ntfy-server ntfy user add --role=admin {{ ntfy_admin_user }}
when: ntfy_admin_user not in ntfy_user_list.stdout
register: ntfy_user_create
changed_when: ntfy_user_create.rc == 0
become_user: "{{ ansible_user }}"
- name: Set admin user password
ansible.builtin.shell: |
printf '%s\n%s\n' '{{ ntfy_admin_password }}' '{{ ntfy_admin_password }}' | podman exec -i ntfy-server ntfy user change-pass {{ ntfy_admin_user }}
when: ntfy_admin_user in ntfy_user_list.stdout
changed_when: false
become_user: "{{ ansible_user }}"
- name: Deploy nginx vhost configuration for ntfy
ansible.builtin.template:
src: nginx-vhost.conf.j2
dest: "{{ nginx_conf_dir | default('/etc/nginx/conf.d') }}/ntfy.conf"
owner: root
group: root
mode: "0644"
when: ntfy_nginx_enabled
notify: Reload nginx
- name: Remove nginx vhost configuration for ntfy
ansible.builtin.file:
path: "{{ nginx_conf_dir | default('/etc/nginx/conf.d') }}/ntfy.conf"
state: absent
when: not ntfy_nginx_enabled
notify: Reload nginx