From b4e8b5f82e942dc5861198d26d19edc3d273b7c2 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Thu, 15 Feb 2024 23:01:26 +0100 Subject: netbox --- roles/netbox/tasks/postgres.yaml | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 roles/netbox/tasks/postgres.yaml (limited to 'roles/netbox/tasks/postgres.yaml') diff --git a/roles/netbox/tasks/postgres.yaml b/roles/netbox/tasks/postgres.yaml new file mode 100644 index 0000000..405ed71 --- /dev/null +++ b/roles/netbox/tasks/postgres.yaml @@ -0,0 +1,59 @@ +--- +- name: Generate Database Password + command: + cmd: 'bash -c "dd if=/dev/urandom bs=1 count=50 status=none | base64"' + creates: /opt/netbox_data/db_key + become_user: netbox + become: true + register: gen_db_key + +- name: Save DB Key + copy: + content: '{{ gen_sec_key.stdout }}' + dest: /opt/netbox_data/db_key + owner: root + group: netbox + mode: '640' + become: true + when: gen_db_key.changed + +- name: Read DB Key + slurp: + src: /opt/netbox_data/db_key + become: true + register: db_key + +- name: Set DB Key + set_fact: + postgres_netbox_db_key: '{{ db_key.content | b64decode }}' + cache: false + +- name: install Packages + apt: + name: + - python3-psycopg2 + - postgresql + become: true + +- name: Create netbox DB + community.postgresql.postgresql_db: + name: netbox + become_user: postgres + become: true + +- name: Create netbox DB User + community.postgresql.postgresql_user: + db: netbox + name: netbox + password: '{{ postgres_netbox_db_key }}' + become_user: postgres + become: true + +- name: Change netbox DB Owner + community.postgresql.postgresql_owner: + db: netbox + new_owner: netbox + obj_type: database + obj_name: netbox + become_user: postgres + become: true -- cgit v1.2.3