From 64f4c9f3c19164b7c3235d92792ad9baaacf5952 Mon Sep 17 00:00:00 2001 From: "a@a.ru" Date: Wed, 15 May 2019 14:15:48 +0300 Subject: [PATCH] Add backward compatibility --- attach_existing_rds.yml | 3 ++- deploy_infra.yml | 3 ++- deploy_software.yml | 5 +++-- group_vars/all.yml.example | 3 ++- roles/{debug => s3_config}/defaults/main.yml | 0 roles/{debug => s3_config}/tasks/main.yml | 22 -------------------- roles/s3_debug/defaults/main.yml | 1 + roles/s3_debug/tasks/main.yml | 21 +++++++++++++++++++ 8 files changed, 31 insertions(+), 27 deletions(-) rename roles/{debug => s3_config}/defaults/main.yml (100%) rename roles/{debug => s3_config}/tasks/main.yml (70%) create mode 100644 roles/s3_debug/defaults/main.yml create mode 100644 roles/s3_debug/tasks/main.yml diff --git a/attach_existing_rds.yml b/attach_existing_rds.yml index 4c61c8d..8605f37 100644 --- a/attach_existing_rds.yml +++ b/attach_existing_rds.yml @@ -5,7 +5,8 @@ - { role: s3, when: "backend|bool == true" } - { role: dynamodb, when: "backend|bool == true" } - { role: attach_existing_rds } - - { role: debug, when: "backend|bool == true and upload_debug_info_to_s3|bool == true" } + - { role: s3_config, when: "backend|bool == true and upload_config_to_s3|bool == true" } + - { role: s3_debug, when: "backend|bool == true and upload_debug_info_to_s3|bool == true" } vars_prompt: - name: "confirmation" prompt: "Are you sure you want to attach the existing RDS? If backend variable is set to True, this action includes creating the S3 and DynamoDB table for storing Terraform state files." diff --git a/deploy_infra.yml b/deploy_infra.yml index dcce016..1820e92 100644 --- a/deploy_infra.yml +++ b/deploy_infra.yml @@ -5,4 +5,5 @@ - { role: s3, when: "backend|bool == true" } - { role: dynamodb, when: "backend|bool == true" } - { role: main_infra } - - { role: debug, when: "backend|bool == true and upload_debug_info_to_s3|bool == true" } + - { role: s3_config, when: "backend|bool == true and upload_config_to_s3|bool == true" } + - { role: s3_debug, when: "backend|bool == true and upload_debug_info_to_s3|bool == true" } diff --git a/deploy_software.yml b/deploy_software.yml index 931f2a1..747a840 100644 --- a/deploy_software.yml +++ b/deploy_software.yml @@ -12,5 +12,6 @@ - name: Save debug files hosts: localhost roles: - - { role: s3, when: "backend|bool == true and upload_debug_info_to_s3|bool == true" } - - { role: debug, when: "backend|bool == true and upload_debug_info_to_s3|bool == true" } + - { role: s3, when: "backend|bool == true and (upload_debug_info_to_s3|bool == true or upload_config_to_s3|bool ==true)" } + - { role: s3_config, when: "backend|bool == true and upload_config_to_s3|bool == true" } + - { role: s3_debug, when: "backend|bool == true and upload_debug_info_to_s3|bool == true" } diff --git a/group_vars/all.yml.example b/group_vars/all.yml.example index c5759a1..d08ced7 100644 --- a/group_vars/all.yml.example +++ b/group_vars/all.yml.example @@ -11,7 +11,8 @@ aws_region: "us-east-1" ## If set to true backend will be uploaded and stored at S3 bucket, so you can easily manage your deployment from any machine. It is highly recommended to do not change this variable backend: true -## If this is set to true along with backend variable, this config file and the log output will be saved to s3 bucket. Please, make sure to name it as all.yml. Otherwise, no upload will be performed +## If this is set to true along with backend variable, this config file/the log output will be saved to s3 bucket. Please, make sure to name the config file "all.yml". Otherwise, no upload will be performed +upload_config_to_s3: true upload_debug_info_to_s3: true ## The bucket and dynamodb_table variables will be used only when backend variable is set to true diff --git a/roles/debug/defaults/main.yml b/roles/s3_config/defaults/main.yml similarity index 100% rename from roles/debug/defaults/main.yml rename to roles/s3_config/defaults/main.yml diff --git a/roles/debug/tasks/main.yml b/roles/s3_config/tasks/main.yml similarity index 70% rename from roles/debug/tasks/main.yml rename to roles/s3_config/tasks/main.yml index cc261de..dd598a9 100644 --- a/roles/debug/tasks/main.yml +++ b/roles/s3_config/tasks/main.yml @@ -1,25 +1,3 @@ -- name: Check log file exists - stat: - path: "{{ playbook_dir }}/log.txt" - register: stat_result - -- name: Upload logs to s3 - aws_s3: - bucket: "{{ prefix }}-{{ bucket }}" - object: log.txt - src: "{{ playbook_dir }}/log.txt" - mode: put - profile: "{{ profile }}" - aws_access_key: "{{ access_key }}" - aws_secret_key: "{{ secret_key }}" - region: "{{ region }}" - vars: - access_key: "{{ aws_access_key|default(omit) }}" - secret_key: "{{ aws_secret_key|default(omit) }}" - profile: "{{ aws_profile|default(omit) }}" - region: "{{ aws_region|default(omit) }}" - when: stat_result.stat.exists == true - - name: Check if config file exists stat: path: "{{ playbook_dir }}/group_vars/all.yml" diff --git a/roles/s3_debug/defaults/main.yml b/roles/s3_debug/defaults/main.yml new file mode 100644 index 0000000..1c7d2a8 --- /dev/null +++ b/roles/s3_debug/defaults/main.yml @@ -0,0 +1 @@ +aws_profile: "default" diff --git a/roles/s3_debug/tasks/main.yml b/roles/s3_debug/tasks/main.yml new file mode 100644 index 0000000..084af1d --- /dev/null +++ b/roles/s3_debug/tasks/main.yml @@ -0,0 +1,21 @@ +- name: Check log file exists + stat: + path: "{{ playbook_dir }}/log.txt" + register: stat_result + +- name: Upload logs to s3 + aws_s3: + bucket: "{{ prefix }}-{{ bucket }}" + object: log.txt + src: "{{ playbook_dir }}/log.txt" + mode: put + profile: "{{ profile }}" + aws_access_key: "{{ access_key }}" + aws_secret_key: "{{ secret_key }}" + region: "{{ region }}" + vars: + access_key: "{{ aws_access_key|default(omit) }}" + secret_key: "{{ aws_secret_key|default(omit) }}" + profile: "{{ aws_profile|default(omit) }}" + region: "{{ aws_region|default(omit) }}" + when: stat_result.stat.exists == true