add script to create new app easily

This commit is contained in:
Gabriel Augendre 2024-10-11 17:41:32 +02:00
parent ed9fe33ccb
commit 3bcb33d76c
2 changed files with 52 additions and 0 deletions

8
new-app Executable file
View file

@ -0,0 +1,8 @@
#!/bin/bash
echo "creating directories for '$1'"
mkdir -p "playbooks/apps/files/$1"
mkdir -p "playbooks/apps/templates/$1"
cp playbooks/apps/template.yaml.dist "playbooks/apps/$1.yaml"
sed -i '' "s/==APP==/$1/g" "playbooks/apps/$1.yaml"
echo "done"

View file

@ -0,0 +1,44 @@
---
- name: ==APP==
hosts: servers
gather_facts: false
tasks:
- name: Create dir
ansible.builtin.file:
path: "{{ dir }}"
state: directory
mode: "0775"
- name: Write files
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ dir }}/"
mode: preserve
with_fileglob:
- files/{{ app_name }}/*
- files/{{ app_name }}/.*
notify:
- Restart service
- name: Write templates
ansible.builtin.template:
src: "{{ item }}"
dest: "{{ dir }}/{{ item | basename | regex_replace('\\.j2$', '') }}"
mode: preserve
with_fileglob:
- templates/{{ app_name }}/*.j2
- templates/{{ app_name }}/.*.j2
notify:
- Restart service
- name: Ensure service is started
community.docker.docker_compose_v2:
project_src: "{{ dir }}"
state: present
handlers:
- name: Restart service
community.docker.docker_compose_v2:
project_src: "{{ dir }}"
state: restarted
vars:
app_name: ==APP==
dir: /mnt/data/{{ app_name }}