infrastructure/roles/postgresql-for-zeitbild_backend/tasks/main.json
2024-10-25 11:10:48 +02:00

85 lines
2.1 KiB
JSON

[
{
"name": "packages",
"become": true,
"ansible.builtin.apt": {
"update_cache": true,
"pkg": [
"acl",
"python3-psycopg2"
]
}
},
{
"name": "user",
"become": true,
"become_user": "postgres",
"community.postgresql.postgresql_user": {
"state": "present",
"name": "{{var_postgresql_for_zeitbild_username}}",
"password": "{{var_postgresql_for_zeitbild_password}}"
},
"environment": {
"PGOPTIONS": "-c password_encryption=scram-sha-256"
}
},
{
"name": "schema",
"become": true,
"become_user": "postgres",
"community.postgresql.postgresql_db": {
"state": "present",
"name": "{{var_postgresql_for_zeitbild_schema}}",
"owner": "{{var_postgresql_for_zeitbild_username}}"
}
},
{
"name": "rights",
"become": true,
"become_user": "postgres",
"community.postgresql.postgresql_privs": {
"state": "present",
"db": "{{var_postgresql_for_zeitbild_schema}}",
"objs": "ALL_IN_SCHEMA",
"roles": "{{var_postgresql_for_zeitbild_username}}",
"privs": "ALL",
"grant_option": true
}
},
{
"name": "structure | fetch",
"delegate_to": "localhost",
"ansible.builtin.git": {
"repo": "{{var_postgresql_for_zeitbild_git_repository_url}}",
"version": "{{var_postgresql_for_zeitbild_git_reference}}",
"dest": "/tmp/zeitbild-datamodel-repo"
}
},
{
"name": "structure | build",
"delegate_to": "localhost",
"ansible.builtin.shell": {
"chdir": "/tmp/zeitbild-datamodel-repo",
"cmd": "tools/build --revision='{{var_postgresql_for_zeitbild_revision}}' --format='postgresql' > /tmp/zeitbild.sql"
}
},
{
"name": "structure | transfer",
"ansible.builtin.copy": {
"src": "/tmp/zeitbild.sql",
"dest": "/tmp/zeitbild.sql"
}
},
{
"name": "structure | apply",
"become": true,
"become_user": "postgres",
"community.postgresql.postgresql_query": {
"db": "{{var_postgresql_for_zeitbild_schema}}",
"login_host": "localhost",
"login_user": "{{var_postgresql_for_zeitbild_username}}",
"login_password": "{{var_postgresql_for_zeitbild_password}}",
"query": "{{lookup('ansible.builtin.file','/tmp/zeitbild.sql')}}"
}
}
]