Skip to content
Snippets Groups Projects
Commit 0eee2857 authored by Torsten Nielsen's avatar Torsten Nielsen :dotted_line_face:
Browse files

Install PostgreSQL create db and user

parent 77eff598
No related branches found
No related tags found
No related merge requests found
...@@ -38,6 +38,12 @@ Add the collections: "community.general" (for capabilities) and "ansible.posix" ...@@ -38,6 +38,12 @@ Add the collections: "community.general" (for capabilities) and "ansible.posix"
`$ ansible-galaxy collection install ansible.posix community.general` `$ ansible-galaxy collection install ansible.posix community.general`
For the PostgreSQL part also install the collection and role
`$ ansible-galaxy collection install community.postgresql`
`$ ansible-galaxy install galaxyproject.postgresql`
Example Playbook Example Playbook
---------------- ----------------
......
--- # defaults --- # defaults
# user-account and server, where oTree is deployed # user-account and server, where oTree is deployed
otree_user: "ot" otree_user: "ot"
# DNS # DNSansible-galaxy collections install ansible.posix community.general
otree_fqdn: "otree.local" otree_fqdn: "otree.local"
# Where is the oTree code deployed from # Where is the oTree code deployed from
otree_repo: "https://gitlab.au.dk/otree/otree_example_apps.git" otree_repo: "https://gitlab.au.dk/otree/otree_example_apps.git"
......
--- # PostgreSQL for oTree --- # PostgreSQL for oTree
- name: Which psycopg2 package
ansible.builtin.debug:
msg: "python{{ (ansible_python.version.major == 3) | ternary('3', '') }}-psycopg2"
- name: Install psycopg2
apt:
name: "python{{ (ansible_python.version.major == 3) | ternary('3', '') }}-psycopg2"
# Install PostgreSQL # Install PostgreSQL
- name: Run the task from the galaxyproject.postgresql role to install PostgreSQL - name: Run the task from the galaxyproject.postgresql role to install PostgreSQL
ansible.builtin.include_role: ansible.builtin.include_role:
name: galaxyproject.postgresql name: galaxyproject.postgresql
vars:
postgresql_install_psycopg2: true
# Create PostgreSQL db
- name: "Create a new database with name {{ otree_user }}"
community.postgresql.postgresql_db:
name: "{{ otree_user }}"
become: true
become_user: postgres
# Create PostgreSQL db-user
- name: "Connect to oTree database {{ otree_user }}, create oTree user {{ otree_user }}"
community.postgresql.postgresql_user:
db: "{{ otree_user }}"
name: "{{ otree_user }}"
password: christmas_tree_o
become: true
become_user: postgres
... ...
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment