Update playbooks/n8n.yml

This commit is contained in:
lorentz 2026-04-20 21:25:05 -04:00
parent dab2403aa5
commit 9cc8a68da3

View file

@ -16,12 +16,60 @@
msg: "n8n_url is required" msg: "n8n_url is required"
when: n8n_url is not defined or n8n_url | length == 0 when: n8n_url is not defined or n8n_url | length == 0
- name: Fail if encryption key is not set
fail:
msg: "n8n_encryption_key is required"
when: n8n_encryption_key is not defined or n8n_encryption_key | length == 0
tasks: tasks:
# 🔎 Check if 1Password item exists
- name: Check if 1Password item exists
shell: |
op item get "{{ stack_name }}" --vault="Automation"
register: op_check
failed_when: false
changed_when: false
environment:
OP_SERVICE_ACCOUNT_TOKEN: "{{ lookup('env','OP_SERVICE_ACCOUNT_TOKEN') }}"
# 🔐 Load existing secrets
- name: Load secrets from 1Password
when: op_check.rc == 0
shell: |
op item get "{{ stack_name }}" --vault="Automation" --format json
register: op_item
environment:
OP_SERVICE_ACCOUNT_TOKEN: "{{ lookup('env','OP_SERVICE_ACCOUNT_TOKEN') }}"
- name: Set secrets from 1Password
when: op_check.rc == 0
set_fact:
n8n_postgres_password: "{{ (op_item.stdout | from_json).fields | selectattr('label','equalto','postgres_password') | map(attribute='value') | first }}"
n8n_encryption_key: "{{ (op_item.stdout | from_json).fields | selectattr('label','equalto','encryption_key') | map(attribute='value') | first }}"
# 🔑 Generate if new
- name: Generate postgres password
when: op_check.rc != 0
set_fact:
n8n_postgres_password: "{{ lookup('password','/dev/null length=32 chars=ascii_letters') }}"
- name: Generate encryption key
when: op_check.rc != 0
set_fact:
n8n_encryption_key: "{{ lookup('password','/dev/null length=64 chars=hexdigits') }}"
# 📦 Store in 1Password
- name: Create 1Password item
when: op_check.rc != 0
shell: |
op item create \
--category="Server" \
--title="{{ stack_name }}" \
--vault="Automation" \
"url=https://{{ n8n_url }}" \
"username={{ n8n_editor_email }}" \
"password={{ n8n_editor_password }}" \
"postgres_password={{ n8n_postgres_password }}" \
"encryption_key={{ n8n_encryption_key }}"
environment:
OP_SERVICE_ACCOUNT_TOKEN: "{{ lookup('env','OP_SERVICE_ACCOUNT_TOKEN') }}"
# 🧱 Infrastructure
- name: Ensure stack directory exists - name: Ensure stack directory exists
file: file:
path: "{{ stack_dir }}" path: "{{ stack_dir }}"
@ -33,6 +81,7 @@
name: pangolin name: pangolin
state: present state: present
# 📄 Templates
- name: Render .env - name: Render .env
template: template:
src: templates/n8n.env.j2 src: templates/n8n.env.j2
@ -44,6 +93,7 @@
src: templates/n8n-compose.yml.j2 src: templates/n8n-compose.yml.j2
dest: "{{ stack_dir }}/compose.yml" dest: "{{ stack_dir }}/compose.yml"
# 🚀 Deploy
- name: Deploy stack - name: Deploy stack
command: docker compose up -d command: docker compose up -d
args: args: