aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormihna123 <mihailonvojinovic@gmail.com>2026-06-02 00:23:33 +0200
committermihna123 <mihailonvojinovic@gmail.com>2026-06-02 00:23:33 +0200
commit2f9dbd07b92f80e82b22e8b5079ad3828a374539 (patch)
tree68faffb7a3a97b505ccfd53a0c1d23c1c71f834e
parentb9378a418f94d1698b1277904e9d7d4a683b461c (diff)
downloadinvoice-2f9dbd07b92f80e82b22e8b5079ad3828a374539.tar.gz
invoice-2f9dbd07b92f80e82b22e8b5079ad3828a374539.zip
refactor: separate init from deploy ansible playbooks
-rw-r--r--ansible/deploy.yaml78
-rw-r--r--ansible/init.yaml60
2 files changed, 64 insertions, 74 deletions
diff --git a/ansible/deploy.yaml b/ansible/deploy.yaml
index 911868d..5c4813a 100644
--- a/ansible/deploy.yaml
+++ b/ansible/deploy.yaml
@@ -1,78 +1,20 @@
- name: Deploy to production
hosts: all
remote_user: root
+ become: true
+ become_user: "{{ username }}"
vars:
app_dir: "/home/{{ username }}/invoice"
nvm_sh_dir: "/home/{{ username }}/.nvm/nvm.sh"
tasks:
- - name: Create system user
- ansible.builtin.user:
- name: "{{ username }}"
- group: users
- create_home: yes
- shell: /bin/bash
- append: yes
-
- - name: Check if invoice directory exists
- ansible.builtin.file:
- path: "{{ app_dir }}"
- state: directory
- owner: "{{ username }}"
- group: users
- mode: "0755"
-
- - name: Add github to known hosts
- become: yes
- become_user: "{{ username }}"
- shell: |
- mkdir -p home/{{ username }}/.ssh/
- ssh-keyscan github.com >> home/{{ username }}/.ssh/known_hosts
- args:
- executable: /bin/bash
-
-
- name: Checkout repo
- ansible.builtin.git:
+ git:
repo: "{{ git_repo }}"
dest: "{{ app_dir }}"
version: main
- force: yes
- become: yes
- become_user: "{{ username }}"
-
- - name: Check if nvm is installed
- ansible.builtin.stat:
- path: "{{ nvm_sh_dir }}"
- register: nvm_stat
-
- - name: Install nvm
- shell: >
- curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh
- | bash
- when: not nvm_stat.stat.exists
- become: yes
- become_user: "{{ username }}"
-
- - name: Install node.js
- shell: |
- . {{ nvm_sh_dir }}
- nvm install 24.13.0
- args:
- executable: /bin/bash
- creates: "/home/{{ username }}/.nvm/versions/node/v24.13.0"
- become: yes
- become_user: "{{ username }}"
-
- - name: Install pm2
- shell: |
- . {{ nvm_sh_dir }}
- npm list -g pm2 || npm install -g pm2
- args:
- executable: /bin/bash
- become: yes
- become_user: "{{ username }}"
+ force: true
- name: Install deps
shell: |
@@ -81,9 +23,6 @@
args:
executable: /bin/bash
chdir: "{{ app_dir }}"
- become: yes
- become_user: "{{ username }}"
-
- name: Build nextjs server
shell: |
@@ -92,21 +31,14 @@
args:
executable: /bin/bash
chdir: "{{ app_dir }}"
- become: yes
- become_user: "{{ username }}"
- name: Sync .next/static
shell: |
rsync -avP {{ app_dir }}/.next/static {{ app_dir }}/.next/standalone/.next/
- become: yes
- become_user: "{{ username }}"
-
- name: Sync public dir
shell: |
rsync -avP {{ app_dir }}/public {{ app_dir }}/.next/standalone/
- become: yes
- become_user: "{{ username }}"
- name: Start/restart pm2 process
shell: |
@@ -115,5 +47,3 @@
args:
executable: /bin/bash
chdir: "{{ app_dir }}/.next/standalone"
- become: yes
- become_user: "{{ username }}"
diff --git a/ansible/init.yaml b/ansible/init.yaml
new file mode 100644
index 0000000..7facd59
--- /dev/null
+++ b/ansible/init.yaml
@@ -0,0 +1,60 @@
+- name: Init server deps
+ hosts: all
+ remote_user: root
+
+ vars:
+ app_dir: "/home/{{ username }}/invoice"
+ nvm_sh_dir: "/home/{{ username }}/.nvm/nvm.sh"
+
+ tasks:
+ - name: Create system user
+ ansible.builtin.user:
+ name: "{{ username }}"
+ group: users
+ create_home: yes
+ shell: /bin/bash
+ append: yes
+
+ - name: Check if invoice directory exists
+ ansible.builtin.file:
+ path: "{{ app_dir }}"
+ state: directory
+ owner: "{{ username }}"
+ group: users
+ mode: "0755"
+
+ - name: Add github to known hosts
+ shell: |
+ mkdir -p home/{{ username }}/.ssh/
+ ssh-keyscan github.com >> home/{{ username }}/.ssh/known_hosts
+ args:
+ executable: /bin/bash
+ become: true
+ become_user: "{{ username }}"
+
+
+ - name: Check if nvm is installed
+ ansible.builtin.stat:
+ path: "{{ nvm_sh_dir }}"
+ register: nvm_stat
+
+ - name: Install nvm
+ shell: >
+ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh
+ | bash
+ when: not nvm_stat.stat.exists
+
+ - name: Install node.js
+ shell: |
+ . {{ nvm_sh_dir }}
+ nvm install 24.13.0
+ args:
+ executable: /bin/bash
+ creates: "/home/{{ username }}/.nvm/versions/node/v24.13.0"
+
+ - name: Install pm2
+ shell: |
+ . {{ nvm_sh_dir }}
+ npm list -g pm2 || npm install -g pm2
+ args:
+ executable: /bin/bash