-
Notifications
You must be signed in to change notification settings - Fork 9
Add Ansible automation for test database setup #72
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,8 @@ aiohttp | |
aiosocks | ||
psycopg2 | ||
SQLAlchemy | ||
|
||
# Machine Learning | ||
pandas | ||
tqdm | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,14 @@ | |
template: template0 | ||
register: fpsd_database_result | ||
|
||
- name: Setup TABLEFUNC extension. | ||
postgresql_ext: | ||
name: tablefunc | ||
db: "{{ fpsd_database_psql_env.PGDATABASE }}" | ||
register: postgres_extension | ||
always_run: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should remove this line still. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
changed_when: false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is unnecessary unless after you remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
become: true | ||
become_user: postgres | ||
|
||
|
@@ -51,16 +59,17 @@ | |
always_run: true | ||
changed_when: false | ||
|
||
- name: Create the raw schema. | ||
command: psql -c 'CREATE SCHEMA raw;' | ||
when: "'raw' not in schemas.stdout" | ||
register: raw_schema_result | ||
- name: Create the raw and features schemata. | ||
command: psql -c 'CREATE SCHEMA {{ item }};' | ||
when: "'item' not in schemas.stdout" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, fixed! |
||
register: "{{ item }}_result" | ||
with_items: | ||
- raw | ||
- features | ||
|
||
- name: List all tables in the raw schema. | ||
command: psql -c '\dt raw.*' | ||
register: tables | ||
always_run: true | ||
changed_when: false | ||
|
||
- name: "Create the tables: crawls, hs_history, frontpage_examples, & frontpage_traces." | ||
command: psql -c '{{ lookup("file", "postgres-schemas/"+item) }}' | ||
|
@@ -88,7 +97,7 @@ | |
state: absent | ||
# If the fpsd database was just created, the test database should | ||
# not exist, so there will be nothing to delete. | ||
when: fpsd_database_result|skipped | ||
when: not fpsd_database_result|skipped | ||
|
||
- name: Create the test database based on fpsd. | ||
postgresql_db: | ||
|
@@ -99,6 +108,6 @@ | |
lc_ctype: en_US.UTF-8 | ||
template: "{{ fpsd_database_psql_env.PGDATABASE }}" | ||
|
||
when: raw_schema_result|changed or raw_schema_tables_result|changed | ||
when: raw_schema_tables_result|changed or postgres_extension|skipped or schemata_results|skipped | ||
become: true | ||
become_user: postgres |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need to always run this--the
state
option defaults to "present," and idempotency is something to strive for in Ansible.