Skip to content

Commit

Permalink
Merge pull request #1 from sitewards/ADHOC-add-post-import
Browse files Browse the repository at this point in the history
Adhoc add post import
  • Loading branch information
aboritskiy authored Aug 22, 2019
2 parents 3fe831e + 107fc02 commit 9c9bddd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@
## http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
import_db_aws_access_key_id: "{{ lookup('env', 'AWS_ACCESS_KEY_ID') }}"
import_db_aws_secret_access_key: "{{ lookup('env', 'AWS_SECRET_ACCESS_KEY') }}"

## Define some sql queries, that are executed after the db is imported
import_db_post_import_sql_queries: []
## The query that should be executed
# - query: ""
6 changes: 6 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
---
- include: "dependencies.yml"
- include: "import.yml"

- name: "Run post import quries"
include: "post_import.yml"
with_items: "{{ import_db_post_import_sql_queries }}"
loop_control:
loop_var: "import_db_post_import_sql_query"
21 changes: 21 additions & 0 deletions tasks/post_import.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: "Execute sql query"
command: >
env MYSQL_PWD={{ import_db_root_password }}
mysql --user=root {{ import_db_database_name }}
--execute="{{ import_db_post_import_sql_query.query }}"
no_log: true
ignore_errors: true
register: import_db_post_import_sql_query_result

- debug:
msg: '{{ import_db_post_import_sql_query_result.stderr | regex_replace(import_db_root_password) }}'
when: import_db_post_import_sql_query_result.stderr != ""

- debug:
msg: '{{ import_db_post_import_sql_query_result.stdout | regex_replace(import_db_root_password) }}'
when: import_db_post_import_sql_query_result.stdout != ""

- fail:
msg: "error in sql querry"
when: import_db_post_import_sql_query_result.stderr != ""

0 comments on commit 9c9bddd

Please sign in to comment.