diff --git a/roles/n8n/defaults/main.yml b/roles/n8n/defaults/main.yml index f08d13b..04c8ed9 100644 --- a/roles/n8n/defaults/main.yml +++ b/roles/n8n/defaults/main.yml @@ -1,7 +1,7 @@ --- # Version to deploy -n8n_version: 0.233.1 +n8n_version: 1.0.5 # Root directory where n8n will be installed n8n_root_dir: /opt/n8n # User account under which n8n will run @@ -14,30 +14,13 @@ n8n_port: 8021 # List of IP / CIDR allowed to access n8n_port n8n_src_ip: [] -n8n_db_server: "{{ mysql_server | default('localhost') }}" -n8n_db_port: 3306 +n8n_db_server: "{{ pg_server | default('localhost') }}" +n8n_db_port: 5432 n8n_db_name: n8n n8n_db_user: n8n # If not defined, a random one will be created and stored in the {{ n8n_root_dir }}/meta/ansible_dbpass #n8n_db_pass: S3cR3t. -# Config dfirectives, will be translated to json in {{ n8n_root_dir }}/etc/n8n.json -n8n_config_base: - database: - type: mysqldb - mysqldb: - database: "{{ n8n_db_name }}" - host: "{{ n8n_db_server }}" - port: "{{ n8n_db_port }}" - user: "{{ n8n_db_user }}" - password: "{{ n8n_db_pass }}" - generic: - timezone: "{{ system_tz | default('Europe/Paris') }}" - port: "{{ n8n_port }}" -# This lets you override just part of the defaults -n8n_config_extra: {} -n8n_config: "{{ n8n_config_base | combine(n8n_config_extra,recursive=True) }}" - # An optional list of extra module to install n8n_extra_node_modules: [] @@ -65,11 +48,6 @@ n8n_mem_limit: 2048 # NODE_FUNCTION_ALLOW_BUILTIN: request-promise-native n8n_env_var: {} -# Should user management be enabled ? -# If False, n8n editor will be accessible wihtout authentication at all -# so be sure to protect it by other mean (eg, at the reverse proxy level) -n8n_user_management: True - # SMTP settings n8n_smtp_server: localhost n8n_smtp_port: 25 diff --git a/roles/n8n/meta/main.yml b/roles/n8n/meta/main.yml index 87eb0ab..3d73026 100644 --- a/roles/n8n/meta/main.yml +++ b/roles/n8n/meta/main.yml @@ -2,5 +2,5 @@ dependencies: - role: repo_nodejs - - role: mysql_server + - role: postgresql_server when: n8n_db_server in ['localhost','127.0.0.1'] diff --git a/roles/n8n/tasks/archive_pre.yml b/roles/n8n/tasks/archive_pre.yml index 9dc61f5..7de4e26 100644 --- a/roles/n8n/tasks/archive_pre.yml +++ b/roles/n8n/tasks/archive_pre.yml @@ -20,18 +20,17 @@ delegate_to: "{{ inventory_hostname }}" tags: n8n -- name: Dump the database - mysql_db: - state: dump - name: "{{ n8n_db_name }}" - target: "{{ n8n_root_dir }}/archives/{{ n8n_current_version }}/{{ n8n_db_name }}.sql.xz" - login_host: "{{ n8n_db_server }}" - login_port: "{{ n8n_db_port }}" - login_user: "{{ n8n_db_user }}" - login_password: "{{ n8n_db_pass }}" - quick: True - single_transaction: True +- name: Backup the database + command: > + /usr/pgsql-15/bin/pg_dump + --format=custom + --clean + --create + --host={{ n8n_db_server }} + --port={{ n8n_db_port }} + --username={{ n8n_db_user }} + {{ n8n_db_name }} + --file={{ n8n_root_dir }}/archives/{{ n8n_current_version }}/{{ n8n_db_name }}.sqlc environment: - XZ_OPT: -T0 + - PGPASSWORD: "{{ n8n_db_pass }}" tags: n8n - diff --git a/roles/n8n/tasks/conf.yml b/roles/n8n/tasks/conf.yml index 5e897df..f486802 100644 --- a/roles/n8n/tasks/conf.yml +++ b/roles/n8n/tasks/conf.yml @@ -3,7 +3,6 @@ - name: Deploy n8n config template: src={{ item }}.j2 dest={{ n8n_root_dir }}/etc/{{ item }} group={{ n8n_user }} mode=640 loop: - - n8n.json - env notify: restart n8n tags: n8n diff --git a/roles/n8n/tasks/install.yml b/roles/n8n/tasks/install.yml index a109c45..538dcf7 100644 --- a/roles/n8n/tasks/install.yml +++ b/roles/n8n/tasks/install.yml @@ -1,7 +1,7 @@ --- - name: Install nodejs and dependencies - yum: + package: name: - nodejs - gcc @@ -9,6 +9,7 @@ - make - sqlite-devel - python3 + - postgresql15 tags: n8n - name: Wipe node_module on upgrade @@ -37,13 +38,29 @@ loop: "{{ n8n_extra_node_modules }}" tags: n8n -# Create the database -- import_tasks: ../includes/webapps_create_mysql_db.yml - vars: - - db_name: "{{ n8n_db_name }}" - - db_user: "{{ n8n_db_user }}" - - db_server: "{{ n8n_db_server }}" - - db_pass: "{{ n8n_db_pass }}" +- name: Create the PostgreSQL role + postgresql_user: + db: postgres + name: "{{ n8n_db_user }}" + password: "{{ n8n_db_pass }}" + login_host: "{{ n8n_db_server }}" + login_port: "{{ n8n_db_port }}" + login_user: sqladmin + login_password: "{{ pg_admin_pass }}" + tags: n8n + +- name: Create the PostgreSQL database + postgresql_db: + name: "{{ n8n_db_name }}" + encoding: UTF-8 + lc_collate: C + lc_ctype: C + template: template0 + owner: "{{ n8n_db_user }}" + login_host: "{{ n8n_db_server }}" + login_port: "{{ n8n_db_port }}" + login_user: sqladmin + login_password: "{{ pg_admin_pass }}" tags: n8n - name: Deploy systemd unit diff --git a/roles/n8n/templates/env.j2 b/roles/n8n/templates/env.j2 index b49d5fc..da16bbf 100644 --- a/roles/n8n/templates/env.j2 +++ b/roles/n8n/templates/env.j2 @@ -1,7 +1,5 @@ -N8N_CONFIG_FILES={{ n8n_root_dir }}/etc/n8n.json +N8N_PORT={{ n8n_port }} N8N_USER_FOLDER={{ n8n_root_dir }}/data -WEBHOOK_URL={{ n8n_public_url }} -VUE_APP_URL_BASE_API={{ n8n_public_url }} N8N_ENCRYPTION_KEY={{ n8n_secret_key | quote }} EXECUTIONS_DATA_PRUNE=true EXECUTIONS_DATA_MAX_AGE={{ n8n_data_max_age }} @@ -10,7 +8,6 @@ N8N_CUSTOM_EXTENSIONS={{ n8n_root_dir }}/.n8n/custom {{ env }}={{ n8n_env_var[env] }} {% endfor %} N8N_DIAGNOSTICS_ENABLED=false -N8N_USER_MANAGEMENT_DISABLED=true N8N_EMAIL_MODE=smtp N8N_SMTP_HOST={{ n8n_smtp_server }} N8N_SMTP_PORT={{ n8n_smtp_port }} @@ -19,7 +16,18 @@ N8N_SMTP_SENDER={{ n8n_smtp_sender }} # Note : n8n requires N8N_SMTP_USER and N8N_SMTP_PASS, even if no login is required for relay N8N_SMTP_USER={{ n8n_smtp_user | default('smtp') }} N8N_SMTP_PASS={{ n8n_smtp_pass | default('smtp') }} -N8N_EDITOR_BASE_URL={{ n8n_public_url }} {% if system_tz is defined %} GENERIC_TIMEZONE={{ system_tz }} {% endif %} + +N8N_HIRING_BANNER_ENABLED=false +VUE_APP_URL_BASE_API={{ n8n_public_url }} +N8N_EDITOR_BASE_URL={{ n8n_public_url }} +WEBHOOK_URL={{ n8n_public_url }} + +DB_TYPE=postgresdb +DB_POSTGRESDB_HOST={{ n8n_db_server }} +DB_POSTGRESDB_PORT={{ n8n_db_port }} +DB_POSTGRESDB_DATABASE={{ n8n_db_name }} +DB_POSTGRESDB_USER={{ n8n_db_user }} +DB_POSTGRESDB_PASSWORD={{ n8n_db_pass }} diff --git a/roles/n8n/templates/n8n.json.j2 b/roles/n8n/templates/n8n.json.j2 deleted file mode 100644 index c7ab036..0000000 --- a/roles/n8n/templates/n8n.json.j2 +++ /dev/null @@ -1 +0,0 @@ -{{ n8n_config | to_nice_json(indent=4) }} diff --git a/roles/n8n/templates/post-backup.sh.j2 b/roles/n8n/templates/post-backup.sh.j2 index 582cb22..cd5ca37 100644 --- a/roles/n8n/templates/post-backup.sh.j2 +++ b/roles/n8n/templates/post-backup.sh.j2 @@ -1,3 +1,3 @@ #!/bin/bash -e -rm -f {{ n8n_root_dir }}/backup/*.sql.zst +rm -f {{ n8n_root_dir }}/backup/*.sqlc diff --git a/roles/n8n/templates/pre-backup.sh.j2 b/roles/n8n/templates/pre-backup.sh.j2 index a25cf0a..0c040ad 100644 --- a/roles/n8n/templates/pre-backup.sh.j2 +++ b/roles/n8n/templates/pre-backup.sh.j2 @@ -2,12 +2,12 @@ set -eo pipefail -/usr/bin/mysqldump \ -{% if n8n_db_server not in ['localhost','127.0.0.1'] %} - --user={{ n8n_db_user | quote }} \ - --password={{ n8n_db_pass | quote }} \ +PGPASSWORD='{{ n8n_db_pass }}' /usr/pgsql-15/bin/pg_dump \ + --format=custom \ + --clean \ + --create \ + --username={{ n8n_db_user | quote }} \ --host={{ n8n_db_server | quote }} \ - --port={{ n8n_db_port | quote }} \ -{% endif %} - --quick --single-transaction \ - --add-drop-table {{ n8n_db_name | quote }} | zstd -c > {{ n8n_root_dir }}/backup/{{ n8n_db_name }}.sql.zst + {{ n8n_db_name | quote }} \ + -f {{ n8n_root_dir }}/backup/{{ n8n_db_name | quote }}.sqlc +