blockscout-terraform/roles/s3/tasks/main.yml

60 lines
1.7 KiB
YAML
Raw Normal View History

- name: Create S3 bucket
2019-02-23 12:47:43 -08:00
aws_s3:
bucket: "{{ prefix }}-{{ bucket }}"
2019-02-23 12:47:43 -08:00
mode: create
2019-02-23 16:16:07 -08:00
permission: private
2019-02-23 12:47:43 -08:00
- name: Apply tags and versioning to create S3 bucket
s3_bucket:
name: "{{ prefix }}-{{ bucket }}"
versioning: yes
tags:
origin: terraform
prefix: "{{ prefix }}"
- name: Add lifecycle management policy to created S3 bucket
s3_lifecycle:
name: "{{ prefix }}-{{ bucket }}"
rule_id: "expire"
noncurrent_version_expiration_days: 90
status: enabled
state: present
- name: Check if config file exists
stat:
path: "{{ playbook_dir }}/group_vars/all.yml"
register: stat_result
when: upload_config_to_s3|bool == True
- name: Copy temporary file to be uploaded
command: "cp {{ playbook_dir }}/group_vars/all.yml {{ playbook_dir }}/group_vars/all.yml.temp"
when: upload_config_to_s3|bool == True
- name: Remove insecure AWS variables
replace:
path: "{{ playbook_dir }}/group_vars/all.yml.temp"
regexp: 'aws_.*'
replace: '<There was an aws-related insecure variable to keep at S3. Removed>'
when: upload_config_to_s3|bool == True
- name: Remove other insecure variables
replace:
path: "{{ playbook_dir }}/group_vars/all.yml.temp"
regexp: 'secret_.*'
replace: '<There was an insecure variable to keep at S3. Removed>'
when: upload_config_to_s3|bool == True
- name: Upload config to S3 bucket
2019-02-23 12:47:43 -08:00
aws_s3:
bucket: "{{ prefix }}-{{ bucket }}"
2019-02-23 16:16:07 -08:00
object: all.yml
src: "{{ playbook_dir }}/group_vars/all.yml.temp"
mode: put
2019-04-09 09:17:59 -07:00
when: upload_config_to_s3|bool == True and stat_result.stat.exists == True
- name: Remove temp file
file:
path: "{{ playbook_dir }}/group_vars/all.yml.temp"
state: absent
when: upload_config_to_s3|bool == True