diff --git a/defaults/main.yml b/defaults/main.yml index da3d4ac..dc0f5ab 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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: "" diff --git a/tasks/main.yml b/tasks/main.yml index db53c6f..1a97228 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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" diff --git a/tasks/post_import.yml b/tasks/post_import.yml new file mode 100644 index 0000000..f11dea5 --- /dev/null +++ b/tasks/post_import.yml @@ -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 != ""