-
Notifications
You must be signed in to change notification settings - Fork 9
Add Ansible automation for test database setup #72
Conversation
afd7bcc
to
0c1170d
Compare
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.
If you weren't aware of this before, for re-testing this I would use ANSIBLE_ARGS="--tags=database -vvv" vagrant provision
(or up
).
Can you change the line when: fpsd_database_result|skipped
to when: not fpsd_database_result|skipped
? Couldn't make a comment on that line because it's either Conor or my own mistake, but it would be good to fix.
|
||
# Machine Learning | ||
pandas | ||
tqdm |
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.
Lack of newline is weird. Don't think it will matter.
@@ -40,6 +40,12 @@ | |||
template: template0 | |||
register: fpsd_database_result | |||
|
|||
- name: Setup TABLEFUNC extension. | |||
postgresql_ext: name=tablefunc db="{{ fpsd_database_psql_env.PGDATABASE }}" |
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.
To be consistent with the rest of the role, the options to postgresql_ext
should each be on their own line.
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.
Not to mention it totally screws up syntax highlighting in my editor with this style.
- 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 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.
postgresql_ext: name=tablefunc db="{{ fpsd_database_psql_env.PGDATABASE }}" | ||
register: postgres_extension | ||
always_run: true | ||
changed_when: false |
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.
This line is unnecessary unless after you remove the run_always
line the task is still showing a changed status even when re-run. Also, we need to know if it changed, because if so, we should delete the testdb and re-create it based on the new template.
@@ -56,6 +62,11 @@ | |||
when: "'raw' not in schemas.stdout" | |||
register: raw_schema_result | |||
|
|||
- name: Create the features schema. |
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.
This can be combined with the last task:
- name: Create the raw and features schemata.
command: psql -c 'CREATE SCHEMA {{ item }};'
when: "'item' not in schemas.stdout"
register: "{{ item }}_result"
with_items:
- raw
- features
@@ -99,6 +110,12 @@ | |||
lc_ctype: en_US.UTF-8 | |||
template: "{{ fpsd_database_psql_env.PGDATABASE }}" | |||
|
|||
when: raw_schema_result|changed or raw_schema_tables_result|changed | |||
- name: Setup TABLEFUNC extension. |
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.
This task shouldn't need to run. The TABLEFUNC extension should come along with the template.
always_run: true | ||
changed_when: false | ||
|
||
when: raw_schema_result|changed or raw_schema_tables_result|changed or features_schema_result|changed |
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.
To reflect our desire to know if the presence of the tablefunc extension has changed, as well as our combining the schemata creation into one task, we would change this to:
when: raw_schema_tables_result|changed or postgres_extension|skipped or schemata_results|skipped
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.
So I've made this: when: raw_schema_tables_result|changed or postgres_extension|skipped or schemas|changed
0c1170d
to
9a06b3d
Compare
Thanks for the comments @fowlslegs!! I've made each suggested change, provisioned the VM again, and executed the tests from the |
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.
For testing purposes, after initial provisioning you should always re-provision (ANSIBLE_ARGS="--tags=database -vvv" vagrant provision
), and check for two things:
- The play succeeds again.
changed=0
in the output (i.e., the play is idempotent).
That's how I caught the syntax mistake in the schemata creation task.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
👍
db: "{{ fpsd_database_psql_env.PGDATABASE }}" | ||
register: postgres_extension | ||
always_run: true | ||
changed_when: false |
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.
This one too.
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.
👍
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 comment
The reason will be displayed to describe this comment to others. Learn more.
You need to use {{ item }}
here. Unlike with your default vars or results registered earlier in the tasklist, which are populated to the local Python task execution environment, you do actually need to use interpolation for each item when looping over an iterable in your with:
directives. Otherwise, this task looks for the literal 'item' in schemas.stdout
, which will always return true, and then the task will run and fail on re-provisioning because it will try to re-create the schemas, returning a non-zero exit code.
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.
Right, fixed!
Ok thanks again for the feedback!! I made these changes, provisioned and re-provisioned and I do get |
Resolves #56