Fix a number of variables
This commit is contained in:
parent
f31883411b
commit
7f7786ae9c
|
@ -2,6 +2,7 @@ log.txt
|
||||||
|
|
||||||
# Terraform State
|
# Terraform State
|
||||||
*.terraform*
|
*.terraform*
|
||||||
|
*.tfstate
|
||||||
*terraform.tfstate.d*
|
*terraform.tfstate.d*
|
||||||
*tfplan*
|
*tfplan*
|
||||||
roles/main_infra/files/backend.tfvars
|
roles/main_infra/files/backend.tfvars
|
||||||
|
@ -33,5 +34,6 @@ host_vars/*
|
||||||
.*.swp
|
.*.swp
|
||||||
|
|
||||||
blockscout-*/
|
blockscout-*/
|
||||||
|
roles/main_infra/files-*
|
||||||
|
|
||||||
hosts
|
hosts
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
with_items:
|
with_items:
|
||||||
- s3
|
- s3
|
||||||
- dynamodb
|
- dynamodb
|
||||||
when: backend|bool == true
|
when: backend | bool
|
||||||
- include_role:
|
- include_role:
|
||||||
name: attach_existing_rds
|
name: attach_existing_rds
|
||||||
always:
|
always:
|
||||||
|
|
18
clean.yml
18
clean.yml
|
@ -1,14 +1,16 @@
|
||||||
- name: Clean TF cache
|
- name: Clean TF cache
|
||||||
hosts: localhost
|
hosts: localhost,all
|
||||||
tasks:
|
tasks:
|
||||||
- name: Clean TF cache
|
- name: Clean TF cache
|
||||||
file:
|
file:
|
||||||
state: absent
|
state: absent
|
||||||
path: "{{ item }}"
|
path: "{{ item }}"
|
||||||
with_items:
|
with_fileglob:
|
||||||
- roles/main_infra/files/.terraform
|
- "roles/main_infra/files/.terraform"
|
||||||
- roles/main_infra/files/terraform.tfstate.d
|
- "roles/main_infra/files/terraform.tfstate.d"
|
||||||
- roles/main_infra/files/main.tfvars
|
- "roles/main_infra/files/main.tfvars"
|
||||||
- roles/main_infra/files/backend.tfvars
|
- "roles/main_infra/files/backend.tfvars"
|
||||||
- roles/main_infra/files/terraform.tfplan
|
- "roles/main_infra/files/terraform.tfplan"
|
||||||
- log.txt
|
- "log.txt"
|
||||||
|
- "blockscout-*"
|
||||||
|
- "/tmp/files-*"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
- name: Prepare infrastructure
|
- name: Prepare infrastructure
|
||||||
hosts: localhost
|
hosts: all
|
||||||
tasks:
|
tasks:
|
||||||
- block:
|
- block:
|
||||||
- include_role:
|
- include_role:
|
||||||
|
@ -9,9 +9,10 @@
|
||||||
with_items:
|
with_items:
|
||||||
- s3
|
- s3
|
||||||
- dynamodb
|
- dynamodb
|
||||||
when: backend|bool == true
|
when: backend | bool
|
||||||
- include_role:
|
- include_role:
|
||||||
name: main_infra
|
name: main_infra
|
||||||
|
when: inventory_hostname == groups[group_names[0]][0]
|
||||||
always:
|
always:
|
||||||
- include_role:
|
- include_role:
|
||||||
name: s3_config
|
name: s3_config
|
||||||
|
|
|
@ -8,10 +8,10 @@
|
||||||
always:
|
always:
|
||||||
- include_role:
|
- include_role:
|
||||||
name: s3
|
name: s3
|
||||||
when: backend|bool == true and (upload_debug_info_to_s3|bool == true or upload_config_to_s3|bool ==true)
|
when: backend|bool and (upload_debug_info_to_s3|bool or upload_config_to_s3|bool)
|
||||||
- include_role:
|
- include_role:
|
||||||
name: s3_config
|
name: s3_config
|
||||||
when: backend|bool == true and upload_config_to_s3|bool == true
|
when: backend|bool and upload_config_to_s3|bool
|
||||||
- include_role:
|
- include_role:
|
||||||
name: s3_debug
|
name: s3_debug
|
||||||
when: backend|bool == true and upload_debug_info_to_s3|bool == true
|
when: backend|bool and upload_debug_info_to_s3|bool
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
- name: Destroy infrastructure
|
- name: Destroy infrastructure
|
||||||
hosts: localhost
|
hosts: all
|
||||||
|
serial: 1
|
||||||
roles:
|
roles:
|
||||||
- { role: destroy, when: "confirmation|bool == True" }
|
- { role: destroy, when: "confirmation|bool == True" }
|
||||||
vars_prompt:
|
vars_prompt:
|
||||||
|
|
|
@ -22,8 +22,8 @@ env_vars:
|
||||||
#ALB_CERTIFICATE_ARN: "arn:aws:acm:us-east-1:290379793816:certificate/6d1bab74-fb46-4244-aab2-832bf519ab24" #ARN of the certificate to attach to the LB. Required if ECTO_USE_SSL is set to true
|
#ALB_CERTIFICATE_ARN: "arn:aws:acm:us-east-1:290379793816:certificate/6d1bab74-fb46-4244-aab2-832bf519ab24" #ARN of the certificate to attach to the LB. Required if ECTO_USE_SSL is set to true
|
||||||
#HEART_BEAT_TIMEOUT: 30 # Heartbeat is an Erlang monitoring service that will restart BlockScout if it becomes unresponsive. This variables configures the timeout before Blockscout will be restarted.
|
#HEART_BEAT_TIMEOUT: 30 # Heartbeat is an Erlang monitoring service that will restart BlockScout if it becomes unresponsive. This variables configures the timeout before Blockscout will be restarted.
|
||||||
#HEART_COMMAND: "sudo systemctl restart explorer.service" # This variable represents a command that is used to restart the service
|
#HEART_COMMAND: "sudo systemctl restart explorer.service" # This variable represents a command that is used to restart the service
|
||||||
BLOCKSCOUT_VERSION: "v1.3.13-beta" # Added to the footer to signify the current BlockScout version
|
#BLOCKSCOUT_VERSION: "v1.3.13-beta" # Added to the footer to signify the current BlockScout version
|
||||||
RELEASE_LINK: "https://github.com/poanetwork/blockscout/releases/tag/v1.3.13-beta" # The link to Blockscout release notes in the footer.
|
#RELEASE_LINK: "https://github.com/poanetwork/blockscout/releases/tag/v1.3.13-beta" # The link to Blockscout release notes in the footer.
|
||||||
#ELIXIR_VERSION: "v1.8.1" # Elixir version to install on the node before Blockscout deploy
|
#ELIXIR_VERSION: "v1.8.1" # Elixir version to install on the node before Blockscout deploy
|
||||||
#BLOCK_TRANSFORMER: "base" # Transformer for blocks: base or clique.
|
#BLOCK_TRANSFORMER: "base" # Transformer for blocks: base or clique.
|
||||||
#GRAPHIQL_TRANSACTION: "0xbc426b4792c48d8ca31ec9786e403866e14e7f3e4d39c7f2852e518fae529ab4" # Random tx hash on the network, used as default for graphiql tx.
|
#GRAPHIQL_TRANSACTION: "0xbc426b4792c48d8ca31ec9786e403866e14e7f3e4d39c7f2852e518fae529ab4" # Random tx hash on the network, used as default for graphiql tx.
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
template:
|
template:
|
||||||
src: roles/main_infra/templates/terraform.tfvars.j2
|
src: roles/main_infra/templates/terraform.tfvars.j2
|
||||||
dest: roles/main_infra/files/terraform.tfvars
|
dest: roles/main_infra/files/terraform.tfvars
|
||||||
vars:
|
|
||||||
db_iops: "{{ chain_db_iops | default({}) }}"
|
|
||||||
|
|
||||||
- name: Generating backend file
|
- name: Generating backend file
|
||||||
template:
|
template:
|
||||||
|
|
|
@ -1,33 +1,27 @@
|
||||||
- name: Check prefix
|
- name: Check prefix
|
||||||
fail:
|
fail:
|
||||||
msg: "The prefix '{{ prefix }}' is invalid. It must consist only of the lowercase characters a-z and digits 0-9, and must be between 3 and 5 characters long."
|
msg: "The prefix '{{ group_names[0] }}' is invalid. It must consist only of the lowercase characters a-z and digits 0-9, and must be between 3 and 5 characters long."
|
||||||
when: prefix|length < 3 or prefix|length > 5 or prefix is not match("^[a-z0-9]+$")
|
when: group_names[0] | length < 3 or group_names[0] | length > 5 or group_names[0] is not match("^[a-z0-9]+$")
|
||||||
|
|
||||||
- name: Check chain names
|
- name: Check chain names
|
||||||
fail:
|
fail:
|
||||||
msg: "The prefix '{{ item }}' is invalid. It must consist only of the lowercase characters a-z and digits 0-9, and must not more than 5 characters long."
|
msg: "The chain '{{ item }}' is invalid. It must consist only of the lowercase characters a-z and digits 0-9, and must not more than 5 characters long."
|
||||||
when: item.key|length > 5 or item.key is not match("^[a-z0-9]+$")
|
when: (item.key | length > 5 or item.key is not match("^[a-z0-9]+$")) and item.key != "all" and item.key != "ungrouped"
|
||||||
with_dict: "{{ chain_custom_environment }}"
|
with_dict: "{{ groups }}"
|
||||||
|
|
||||||
- name: Check if terraform is installed
|
- name: Check if terraform is installed
|
||||||
command: which terraform
|
command: "{{ terraform_location }} --version"
|
||||||
register: terraform_status
|
register: terraform_status
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Terraform check result
|
|
||||||
fail:
|
|
||||||
msg: "Terraform is not installed"
|
|
||||||
when: terraform_status.stdout == ""
|
|
||||||
|
|
||||||
- name: Check if python is installed
|
- name: Check if python is installed
|
||||||
command: which python
|
command: "{{ ansible_python_interpreter }} --version"
|
||||||
register: python_status
|
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Python check result
|
- name: Python check result
|
||||||
fail:
|
fail:
|
||||||
msg: "Python either is not installed or is too old. Please install python version 2.6 or higher"
|
msg: "Python is too old. Please install python version 2.6 or higher"
|
||||||
when: python_status.stdout == "" or python_int_version|int < 260
|
when: python_int_version | int < 260
|
||||||
vars:
|
vars:
|
||||||
python_int_version: "{{ ansible_python_version.split('.')[0]|int * 100 + ansible_python_version.split('.')[1]|int * 10 + ansible_python_version.split('.')[2]|int }}"
|
python_int_version: "{{ ansible_python_version.split('.')[0]|int * 100 + ansible_python_version.split('.')[1]|int * 10 + ansible_python_version.split('.')[2]|int }}"
|
||||||
|
|
||||||
|
|
|
@ -10,26 +10,24 @@
|
||||||
state: absent
|
state: absent
|
||||||
dest: roles/main_infra/files/remote-backend-selector.tf
|
dest: roles/main_infra/files/remote-backend-selector.tf
|
||||||
when:
|
when:
|
||||||
- backend | default ('false') | bool != true
|
- not backend | default ('false') | bool
|
||||||
|
|
||||||
- name: Generating variables file
|
- name: Generating variables file
|
||||||
template:
|
template:
|
||||||
src: roles/main_infra/templates/terraform.tfvars.j2
|
src: roles/main_infra/templates/terraform.tfvars.j2
|
||||||
dest: roles/main_infra/files/terraform.tfvars
|
dest: roles/main_infra/files/terraform.tfvars
|
||||||
vars:
|
|
||||||
db_iops: "{{ chain_db_iops | default({}) }}"
|
|
||||||
|
|
||||||
- name: Generating backend file
|
- name: Generating backend file
|
||||||
template:
|
template:
|
||||||
src: roles/main_infra/templates/backend.tfvars.j2
|
src: roles/main_infra/templates/backend.tfvars.j2
|
||||||
dest: roles/main_infra/files/backend.tfvars
|
dest: roles/main_infra/files/backend.tfvars
|
||||||
when: backend|bool == true
|
when: backend | bool
|
||||||
|
|
||||||
- name: Generate Terraform files
|
- name: Generate Terraform files
|
||||||
template:
|
template:
|
||||||
src: "{{ item.key }}"
|
src: "{{ item.key }}"
|
||||||
dest: "{{ item.value }}"
|
dest: "{{ item.value }}"
|
||||||
with_dict: {roles/main_infra/templates/hosts.tf.j2: roles/main_infra/files/hosts.tf,roles/main_infra/templates/routing.tf.j2: roles/main_infra/files/routing.tf,roles/main_infra/templates/provider.tf.j2: roles/main_infra/files/provider.tf}
|
with_dict: { roles/main_infra/templates/hosts.tf.j2: roles/main_infra/files/hosts.tf, roles/main_infra/templates/routing.tf.j2: roles/main_infra/files/routing.tf, roles/main_infra/templates/provider.tf.j2: roles/main_infra/files/provider.tf }
|
||||||
|
|
||||||
# This is due to the TF0.11 bug which do not allow to completely destroy resources if interpolation syntax is used in outputs.tf at edge cases
|
# This is due to the TF0.11 bug which do not allow to completely destroy resources if interpolation syntax is used in outputs.tf at edge cases
|
||||||
- name: Check if outputs.tf exists
|
- name: Check if outputs.tf exists
|
||||||
|
@ -49,7 +47,7 @@
|
||||||
file:
|
file:
|
||||||
path: roles/main_infra/files/.terraform/
|
path: roles/main_infra/files/.terraform/
|
||||||
state: absent
|
state: absent
|
||||||
when: stat_result.stat.exists == True
|
when: stat_result.stat.exists
|
||||||
|
|
||||||
- name: Terraform destroy main infra
|
- name: Terraform destroy main infra
|
||||||
shell: "echo yes | {{ terraform_location }} {{ item }}"
|
shell: "echo yes | {{ terraform_location }} {{ item }}"
|
||||||
|
@ -61,10 +59,6 @@
|
||||||
|
|
||||||
- name: Delete vars from parameter store
|
- name: Delete vars from parameter store
|
||||||
include: parameter_store.yml
|
include: parameter_store.yml
|
||||||
loop: "{{ chain_custom_environment.keys() }}"
|
|
||||||
loop_control:
|
|
||||||
loop_var: chain
|
|
||||||
index_var: index
|
|
||||||
|
|
||||||
- name: Check if outputs.tf.backup exists
|
- name: Check if outputs.tf.backup exists
|
||||||
stat: path=roles/main_infra/files/outputs.tf.backup
|
stat: path=roles/main_infra/files/outputs.tf.backup
|
||||||
|
@ -78,6 +72,12 @@
|
||||||
pause:
|
pause:
|
||||||
prompt: "Do you want to delete S3 bucket with state file and DynamoDB attached to it also? [Yes/No] Default: No"
|
prompt: "Do you want to delete S3 bucket with state file and DynamoDB attached to it also? [Yes/No] Default: No"
|
||||||
register: user_answer
|
register: user_answer
|
||||||
|
until: user_answer.user_input | lower in conditional
|
||||||
|
retries: 10000
|
||||||
|
delay: 1
|
||||||
|
vars:
|
||||||
|
conditional: ['yes','no','true','false']
|
||||||
|
when: inventory_hostname == groups['all'][0]
|
||||||
|
|
||||||
- name: Destroy S3 bucket
|
- name: Destroy S3 bucket
|
||||||
s3_bucket:
|
s3_bucket:
|
||||||
|
@ -93,7 +93,7 @@
|
||||||
secret_key: "{{ aws_secret_key|default(omit) }}"
|
secret_key: "{{ aws_secret_key|default(omit) }}"
|
||||||
profile: "{{ aws_profile|default(omit) }}"
|
profile: "{{ aws_profile|default(omit) }}"
|
||||||
region: "{{ aws_region|default(omit) }}"
|
region: "{{ aws_region|default(omit) }}"
|
||||||
when: user_answer.user_input|bool == True
|
when: hostvars[groups['all'][0]].user_answer.user_input | bool
|
||||||
|
|
||||||
- dynamodb_table:
|
- dynamodb_table:
|
||||||
name: "{{ prefix }}-{{ dynamodb_table }}"
|
name: "{{ prefix }}-{{ dynamodb_table }}"
|
||||||
|
@ -107,4 +107,4 @@
|
||||||
secret_key: "{{ aws_secret_key|default(omit) }}"
|
secret_key: "{{ aws_secret_key|default(omit) }}"
|
||||||
profile: "{{ aws_profile|default(omit) }}"
|
profile: "{{ aws_profile|default(omit) }}"
|
||||||
region: "{{ aws_region|default(omit) }}"
|
region: "{{ aws_region|default(omit) }}"
|
||||||
when: user_answer.user_input|bool == True
|
when: hostvars[groups['all'][0]].user_answer.user_input | bool
|
||||||
|
|
|
@ -2,19 +2,19 @@
|
||||||
set_fact:
|
set_fact:
|
||||||
chain_env: "{{ lookup('aws_ssm', path, aws_access_key=aws_access_key, aws_secret_key=aws_secret_key, region=region, shortnames=true, bypath=true, recursive=true ) }}"
|
chain_env: "{{ lookup('aws_ssm', path, aws_access_key=aws_access_key, aws_secret_key=aws_secret_key, region=region, shortnames=true, bypath=true, recursive=true ) }}"
|
||||||
vars:
|
vars:
|
||||||
path: "/{{ prefix }}/{{ chain }}"
|
path: "/{{ group_names[0] }}/{{ chain }}"
|
||||||
when: aws_access_key is defined
|
when: aws_access_key is defined
|
||||||
|
|
||||||
- name: Fetch environment variables (via profile)
|
- name: Fetch environment variables (via profile)
|
||||||
set_fact:
|
set_fact:
|
||||||
chain_env: "{{ lookup('aws_ssm', path, aws_profile=aws_profile, shortnames=true, bypath=true, recursive=true ) }}"
|
chain_env: "{{ lookup('aws_ssm', path, aws_profile=aws_profile, shortnames=true, bypath=true, recursive=true ) }}"
|
||||||
vars:
|
vars:
|
||||||
path: "/{{ prefix }}/{{ chain }}"
|
path: "/{{ group_names[0] }}/{{ chain }}"
|
||||||
when: aws_profile is defined
|
when: aws_profile is defined
|
||||||
|
|
||||||
- name: Remove chain variables
|
- name: Remove chain variables
|
||||||
aws_ssm_parameter_store:
|
aws_ssm_parameter_store:
|
||||||
name: "/{{ prefix }}/{{ chain }}/{{ item.key }}"
|
name: "/{{ group_names[0] }}/{{ chain }}/{{ item.key }}"
|
||||||
value: "{{ item.value }}"
|
value: "{{ item.value }}"
|
||||||
state: absent
|
state: absent
|
||||||
profile: "{{ profile }}"
|
profile: "{{ profile }}"
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
- name: Create DynamoDB table
|
- name: Create DynamoDB table
|
||||||
dynamodb_table:
|
dynamodb_table:
|
||||||
name: "{{ prefix }}-{{ dynamodb_table }}"
|
name: "{{ group_names[0] }}-{{ dynamodb_table }}"
|
||||||
hash_key_name: LockID
|
hash_key_name: LockID
|
||||||
hash_key_type: STRING
|
hash_key_type: STRING
|
||||||
read_capacity: 1
|
read_capacity: 1
|
||||||
write_capacity: 1
|
write_capacity: 1
|
||||||
tags:
|
tags:
|
||||||
origin: terraform
|
origin: terraform
|
||||||
prefix: "{{ prefix }}"
|
prefix: "{{ group_names[0] }}"
|
||||||
profile: "{{ profile }}"
|
profile: "{{ profile }}"
|
||||||
aws_access_key: "{{ access_key }}"
|
aws_access_key: "{{ access_key }}"
|
||||||
aws_secret_key: "{{ secret_key }}"
|
aws_secret_key: "{{ secret_key }}"
|
||||||
|
|
|
@ -9,3 +9,4 @@ db_subnet_cidr: "10.0.2.0/16"
|
||||||
dns_zone_name: "poa.internal"
|
dns_zone_name: "poa.internal"
|
||||||
instance_type: "m5.large"
|
instance_type: "m5.large"
|
||||||
root_block_size: 8
|
root_block_size: 8
|
||||||
|
db_iops: {}
|
||||||
|
|
|
@ -1,53 +1,68 @@
|
||||||
|
- name: Ansible delete file glob
|
||||||
|
find:
|
||||||
|
paths: /tmp/
|
||||||
|
file_type: directory
|
||||||
|
patterns: "files-{{ group_names[0] }}"
|
||||||
|
register: files_to_delete
|
||||||
|
|
||||||
|
- name: Ansible remove file glob
|
||||||
|
file:
|
||||||
|
path: "{{ item.path }}"
|
||||||
|
state: absent
|
||||||
|
with_items: "{{ files_to_delete.files }}"
|
||||||
|
|
||||||
|
- name: Copy files
|
||||||
|
copy:
|
||||||
|
src: "roles/main_infra/files/"
|
||||||
|
dest: "/tmp/files-{{ group_names[0] }}/"
|
||||||
|
|
||||||
- name: Local or remote backend selector (remote)
|
- name: Local or remote backend selector (remote)
|
||||||
template:
|
template:
|
||||||
src: remote-backend-selector.tf.j2
|
src: remote-backend-selector.tf.j2
|
||||||
dest: roles/main_infra/files/remote-backend-selector.tf
|
dest: "/tmp/files-{{ group_names[0] }}/remote-backend-selector.tf"
|
||||||
when:
|
when:
|
||||||
- backend|bool
|
- backend | bool
|
||||||
|
|
||||||
- name: Local or remote backend selector (local)
|
- name: Local or remote backend selector (local)
|
||||||
file:
|
file:
|
||||||
state: absent
|
state: absent
|
||||||
dest: roles/main_infra/files/remote-backend-selector.tf
|
dest: "/tmp/files-{{ group_names[0] }}/remote-backend-selector.tf"
|
||||||
when:
|
when:
|
||||||
- backend | default('false') | bool
|
- not backend | default('false') | bool
|
||||||
|
|
||||||
- name: Generating variables file
|
- name: Generating variables file
|
||||||
template:
|
template:
|
||||||
src: terraform.tfvars.j2
|
src: terraform.tfvars.j2
|
||||||
dest: roles/main_infra/files/terraform.tfvars
|
dest: "/tmp/files-{{ group_names[0] }}/terraform.tfvars"
|
||||||
vars:
|
|
||||||
db_iops: "{{ db_iops | default({}) }}"
|
|
||||||
|
|
||||||
- name: Generating backend file
|
- name: Generating backend file
|
||||||
template:
|
template:
|
||||||
src: backend.tfvars.j2
|
src: backend.tfvars.j2
|
||||||
dest: roles/main_infra/files/backend.tfvars
|
dest: "/tmp/files-{{ group_names[0] }}/backend.tfvars"
|
||||||
when: backend | default('false') | bool
|
when: backend | default('false') | bool
|
||||||
|
|
||||||
- name: Check if .terraform folder exists
|
- name: Remove Terraform state
|
||||||
stat:
|
|
||||||
path: "roles/main_infra/files/.terraform/"
|
|
||||||
register: stat_result
|
|
||||||
|
|
||||||
- name: Remove .terraform folder
|
|
||||||
file:
|
file:
|
||||||
path: roles/main_infra/files/.terraform/
|
path: "{{ item }}"
|
||||||
state: absent
|
state: absent
|
||||||
when: stat_result.stat.exists
|
with_items:
|
||||||
|
- "/tmp/files-{{ group_names[0] }}/.terraform/"
|
||||||
|
- "/tmp/files-{{ group_names[0] }}/terraform.tfstate"
|
||||||
|
- "/tmp/files-{{ group_names[0] }}/terraform.tfstate.backup"
|
||||||
|
- "/tmp/files-{{ group_names[0] }}/terraform.tfplan"
|
||||||
|
|
||||||
- name: Generate Terraform files
|
- name: Generate Terraform files
|
||||||
template:
|
template:
|
||||||
src: "{{ item.key }}"
|
src: "{{ item.key }}"
|
||||||
dest: "{{ item.value }}"
|
dest: "{{ item.value }}"
|
||||||
with_dict: { hosts.tf.j2: roles/main_infra/files/hosts.tf, routing.tf.j2: roles/main_infra/files/routing.tf, provider.tf.j2: roles/main_infra/files/provider.tf }
|
with_dict: { hosts.tf.j2: "/tmp/files-{{ group_names[0] }}/hosts.tf", routing.tf.j2: "/tmp/files-{{ group_names[0] }}/routing.tf", provider.tf.j2: "/tmp/files-{{ group_names[0] }}/provider.tf" }
|
||||||
|
|
||||||
#Workaround since terraform module return unexpected error.
|
#Workaround since terraform module return unexpected error.
|
||||||
- name: Terraform plan construct
|
- name: Terraform plan construct
|
||||||
shell: "echo yes | {{ terraform_location }} {{ item }}"
|
shell: "echo yes | {{ terraform_location }} {{ item }}"
|
||||||
register: tf_plan
|
register: tf_plan
|
||||||
args:
|
args:
|
||||||
chdir: "roles/main_infra/files"
|
chdir: "/tmp/files-{{ group_names[0] }}"
|
||||||
with_items:
|
with_items:
|
||||||
- "init{{ ' -backend-config=backend.tfvars' if backend|bool == true else '' }}"
|
- "init{{ ' -backend-config=backend.tfvars' if backend|bool == true else '' }}"
|
||||||
- plan -out terraform.tfplan
|
- plan -out terraform.tfplan
|
||||||
|
@ -61,35 +76,51 @@
|
||||||
pause:
|
pause:
|
||||||
prompt: "Are you absolutely sure you want to execute the deployment plan shown above? [False]"
|
prompt: "Are you absolutely sure you want to execute the deployment plan shown above? [False]"
|
||||||
register: user_answer
|
register: user_answer
|
||||||
until: user_answer.user_input | lower != "false" and user_answer.user_input | lower != "no" and user_answer.user_input | lower != "true" and user_answer.user_input | lower != "yes"
|
until: user_answer.user_input | lower in conditional
|
||||||
retries: 10000
|
retries: 10000
|
||||||
delay: 1
|
delay: 1
|
||||||
|
vars:
|
||||||
|
conditional: ['yes','no','true','false']
|
||||||
|
when: inventory_hostname == groups['all'][0]
|
||||||
|
|
||||||
- name: Insert vars into parameter store
|
- name: Insert vars into parameter store
|
||||||
include: parameter_store.yml
|
include: parameter_store.yml
|
||||||
when: user_answer.user_input | bool
|
when: hostvars[groups['all'][0]].user_answer.user_input | bool
|
||||||
|
|
||||||
- name: Terraform provisioning
|
- name: Terraform provisioning
|
||||||
shell: "echo yes | {{ terraform_location }} apply terraform.tfplan"
|
shell: "echo yes | {{ terraform_location }} apply terraform.tfplan"
|
||||||
args:
|
args:
|
||||||
chdir: "roles/main_infra/files"
|
chdir: "/tmp/files-{{ group_names[0] }}"
|
||||||
when: user_answer.user_input | bool
|
when: hostvars[groups['all'][0]].user_answer.user_input | bool
|
||||||
ignore_errors: True
|
ignore_errors: True
|
||||||
|
|
||||||
- name: Ensure Terraform resources has been provisioned
|
- name: Ensure Terraform resources has been provisioned
|
||||||
shell: "echo yes | {{ terraform_location }} apply"
|
shell: "echo yes | {{ terraform_location }} apply"
|
||||||
args:
|
args:
|
||||||
chdir: "roles/main_infra/files"
|
chdir: "/tmp/files-{{ group_names[0] }}"
|
||||||
when: user_answer.user_input | bool
|
when: hostvars[groups['all'][0]].user_answer.user_input | bool
|
||||||
|
|
||||||
- name: Terraform output info into variable
|
- name: Terraform output info into variable
|
||||||
shell: "{{ terraform_location }} output -json"
|
shell: "{{ terraform_location }} output -json"
|
||||||
register: output
|
register: output
|
||||||
args:
|
args:
|
||||||
chdir: "roles/main_infra/files"
|
chdir: "/tmp/files-{{ group_names[0] }}"
|
||||||
when: user_answer.user_input | bool
|
when: hostvars[groups['all'][0]].user_answer.user_input | bool
|
||||||
|
|
||||||
- name: Output info from Terraform
|
- name: Output info from Terraform
|
||||||
debug:
|
debug:
|
||||||
var: output.stdout_lines
|
var: output.stdout_lines
|
||||||
when: user_answer.user_input | bool
|
when: hostvars[groups['all'][0]].user_answer.user_input | bool
|
||||||
|
|
||||||
|
- name: Ansible delete file glob
|
||||||
|
find:
|
||||||
|
paths: /tmp/
|
||||||
|
file_type: directory
|
||||||
|
patterns: "files-{{ group_names[0] }}"
|
||||||
|
register: files_to_delete
|
||||||
|
|
||||||
|
- name: Ansible remove file glob
|
||||||
|
file:
|
||||||
|
path: "{{ item.path }}"
|
||||||
|
state: absent
|
||||||
|
with_items: "{{ files_to_delete.files }}"
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
- name: Insert variables in PS
|
- name: Insert variables in PS
|
||||||
aws_ssm_parameter_store:
|
aws_ssm_parameter_store:
|
||||||
name: "/{{ prefix }}/{{ chain }}/{{ item.key }}"
|
name: "/{{ group_names[0] }}/{{ chain }}/{{ item.key }}"
|
||||||
value: "{{ item.value }}"
|
value: "{{ item.value }}"
|
||||||
profile: "{{ profile }}"
|
profile: "{{ profile }}"
|
||||||
aws_access_key: "{{ access_key }}"
|
aws_access_key: "{{ access_key }}"
|
||||||
|
|
|
@ -39,22 +39,22 @@ resource "aws_launch_configuration" "explorer" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{% for key, value in env_vars.iteritems() %}
|
{% for key in groups[group_names[0]] %}
|
||||||
{% if value['USE_PLACEMENT_GROUP']|default('true') == "true" %}
|
{% if use_placement_group | default('true') == "true" %}
|
||||||
resource "aws_placement_group" "explorer-{{key}}" {
|
resource "aws_placement_group" "explorer-{{ hostvars[key]['chain'] }}" {
|
||||||
name = "${var.prefix}-{{key}}-explorer-pg"
|
name = "${var.prefix}-{{ hostvars[key]['chain'] }}-explorer-pg"
|
||||||
strategy = "cluster"
|
strategy = "cluster"
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% for key, value in env_vars.iteritems() %}
|
{% for key in groups[group_names[0]] %}
|
||||||
resource "aws_autoscaling_group" "explorer-{{key}}" {
|
resource "aws_autoscaling_group" "explorer-{{ hostvars[key]['chain'] }}" {
|
||||||
name = "${aws_launch_configuration.explorer.name}-asg-{{key}}"
|
name = "${aws_launch_configuration.explorer.name}-asg-{{ hostvars[key]['chain'] }}"
|
||||||
max_size = "4"
|
max_size = "4"
|
||||||
min_size = "1"
|
min_size = "1"
|
||||||
desired_capacity = "1"
|
desired_capacity = "1"
|
||||||
{% if use_placement_group | default('false') == "true" %} placement_group = "${var.prefix}-{{key}}-explorer-pg"
|
{% if use_placement_group | default('false') == "true" %} placement_group = "${var.prefix}-{{ hostvars[key]['chain'] }}-explorer-pg"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
launch_configuration = "${aws_launch_configuration.explorer.name}"
|
launch_configuration = "${aws_launch_configuration.explorer.name}"
|
||||||
vpc_zone_identifier = ["${aws_subnet.default.id}"]
|
vpc_zone_identifier = ["${aws_subnet.default.id}"]
|
||||||
|
@ -92,29 +92,29 @@ resource "aws_autoscaling_group" "explorer-{{key}}" {
|
||||||
|
|
||||||
tag {
|
tag {
|
||||||
key = "chain"
|
key = "chain"
|
||||||
value = "{{ key }}"
|
value = "{{ hostvars[key]['chain'] }}"
|
||||||
propagate_at_launch = true
|
propagate_at_launch = true
|
||||||
}
|
}
|
||||||
|
|
||||||
tag {
|
tag {
|
||||||
key = "Name"
|
key = "Name"
|
||||||
value = "{{ key }} Application"
|
value = "{{ hostvars[key]['chain'] }} Application"
|
||||||
propagate_at_launch = true
|
propagate_at_launch = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: These autoscaling policies are not currently wired up to any triggers
|
# TODO: These autoscaling policies are not currently wired up to any triggers
|
||||||
resource "aws_autoscaling_policy" "explorer-up" {
|
resource "aws_autoscaling_policy" "explorer-up-{{ hostvars[key]['chain'] }}" {
|
||||||
name = "${var.prefix}-{{key}}-explorer-autoscaling-policy-up"
|
name = "${var.prefix}-{{ hostvars[key]['chain'] }}-explorer-autoscaling-policy-up"
|
||||||
autoscaling_group_name = "${aws_autoscaling_group.explorer-{{key}}.name}"
|
autoscaling_group_name = "${aws_autoscaling_group.explorer-{{ hostvars[key]['chain'] }}.name}"
|
||||||
adjustment_type = "ChangeInCapacity"
|
adjustment_type = "ChangeInCapacity"
|
||||||
scaling_adjustment = 1
|
scaling_adjustment = 1
|
||||||
cooldown = 300
|
cooldown = 300
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_autoscaling_policy" "explorer-down" {
|
resource "aws_autoscaling_policy" "explorer-down-{{ hostvars[key]['chain'] }}" {
|
||||||
name = "${var.prefix}-{{key}}-explorer-autoscaling-policy-down"
|
name = "${var.prefix}-{{ hostvars[key]['chain'] }}-explorer-autoscaling-policy-down"
|
||||||
autoscaling_group_name = "${aws_autoscaling_group.explorer-{{key}}.name}"
|
autoscaling_group_name = "${aws_autoscaling_group.explorer-{{ hostvars[key]['chain'] }}.name}"
|
||||||
adjustment_type = "ChangeInCapacity"
|
adjustment_type = "ChangeInCapacity"
|
||||||
scaling_adjustment = -1
|
scaling_adjustment = -1
|
||||||
cooldown = 300
|
cooldown = 300
|
||||||
|
|
|
@ -58,12 +58,12 @@ resource "aws_lb_target_group" "explorer" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{% for key, value in env_vars.iteritems() %}
|
{% for host in groups[group_names[0]] %}
|
||||||
resource "aws_alb_listener" "alb_listener{{loop.index-1}}" {
|
resource "aws_alb_listener" "alb_listener{{loop.index-1}}" {
|
||||||
load_balancer_arn = "${aws_lb.explorer.*.arn[{{loop.index-1}}]}"
|
load_balancer_arn = "${aws_lb.explorer.*.arn[{{loop.index-1}}]}"
|
||||||
port = "${lookup(var.use_ssl,element(var.chains,{{loop.index-1}})) ? "443" : "80" }"
|
port = "${lookup(var.use_ssl,element(var.chains,{{loop.index-1}})) ? "443" : "80" }"
|
||||||
protocol = "${lookup(var.use_ssl,element(var.chains,{{loop.index-1}})) ? "HTTPS" : "HTTP" }"
|
protocol = "${lookup(var.use_ssl,element(var.chains,{{loop.index-1}})) ? "HTTPS" : "HTTP" }"
|
||||||
{% if value['ECTO_USE_SSL']|default('false') == "true" %}
|
{% if hostvars[host]['env_vars']['ECTO_USE_SSL']|default('false') == "true" %}
|
||||||
ssl_policy = "${lookup(var.alb_ssl_policy,element(var.chains,{{loop.index-1}}))}"
|
ssl_policy = "${lookup(var.alb_ssl_policy,element(var.chains,{{loop.index-1}}))}"
|
||||||
certificate_arn = "${lookup(var.alb_certificate_arn,element(var.chains,{{loop.index-1}}))}"
|
certificate_arn = "${lookup(var.alb_certificate_arn,element(var.chains,{{loop.index-1}}))}"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -45,55 +45,55 @@ chains = [
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
]
|
]
|
||||||
|
|
||||||
db_id = {
|
chain_db_id = {
|
||||||
{% for host in groups[group_names[0]] %}
|
{% for host in groups[group_names[0]] %}
|
||||||
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_id'] }}"{% if not loop.last %},{% endif %}
|
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_id'] }}"{% if not loop.last %},{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
}
|
}
|
||||||
|
|
||||||
db_name = {
|
chain_db_name = {
|
||||||
{% for host in groups[group_names[0]] %}
|
{% for host in groups[group_names[0]] %}
|
||||||
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_name'] }}"{% if not loop.last %},{% endif %}
|
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_name'] }}"{% if not loop.last %},{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
}
|
}
|
||||||
|
|
||||||
db_username = {
|
chain_db_username = {
|
||||||
{% for host in groups[group_names[0]] %}
|
{% for host in groups[group_names[0]] %}
|
||||||
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_username'] }}"{% if not loop.last %},{% endif %}
|
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_username'] }}"{% if not loop.last %},{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
}
|
}
|
||||||
|
|
||||||
db_password = {
|
chain_db_password = {
|
||||||
{% for host in groups[group_names[0]] %}
|
{% for host in groups[group_names[0]] %}
|
||||||
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_password'] }}"{% if not loop.last %},{% endif %}
|
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_password'] }}"{% if not loop.last %},{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
}
|
}
|
||||||
|
|
||||||
db_instance_class = {
|
chain_db_instance_class = {
|
||||||
{% for host in groups[group_names[0]] %}
|
{% for host in groups[group_names[0]] %}
|
||||||
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_instance_class'] }}"{% if not loop.last %},{% endif %}
|
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_instance_class'] }}"{% if not loop.last %},{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
}
|
}
|
||||||
|
|
||||||
db_storage = {
|
chain_db_storage = {
|
||||||
{% for host in groups[group_names[0]] %}
|
{% for host in groups[group_names[0]] %}
|
||||||
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_storage'] }}"{% if not loop.last %},{% endif %}
|
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_storage'] }}"{% if not loop.last %},{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
}
|
}
|
||||||
|
|
||||||
db_storage_type = {
|
chain_db_storage_type = {
|
||||||
{% for host in groups[group_names[0]] %}
|
{% for host in groups[group_names[0]] %}
|
||||||
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_storage_type'] }}"{% if not loop.last %},{% endif %}
|
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_storage_type'] }}"{% if not loop.last %},{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
}
|
}
|
||||||
|
|
||||||
db_iops = {
|
chain_db_iops = {
|
||||||
{% for host in groups[group_names[0]] %}
|
{% for host in groups[group_names[0]] %}
|
||||||
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_iops'] }}"{% if not loop.last %},{% endif %}
|
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_iops']|default('0') }}"{% if not loop.last %},{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
}
|
}
|
||||||
|
|
||||||
db_version = {
|
chain_db_version = {
|
||||||
{% for host in groups[group_names[0]] %}
|
{% for host in groups[group_names[0]] %}
|
||||||
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_version'] }}"{% if not loop.last %},{% endif %}
|
{{ hostvars[host]['chain'] }} = "{{ hostvars[host]['db_version'] }}"{% if not loop.last %},{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
- name: Clone BlockScout
|
- name: Clone BlockScout
|
||||||
git:
|
git:
|
||||||
repo: "{{ blockscout_repo }}"
|
repo: "{{ blockscout_repo }}"
|
||||||
dest: "blockscout-{{ group_names[0] }}-{{ chain }}"
|
dest: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}"
|
||||||
version: "{{ branch }}"
|
version: "{{ branch }}"
|
||||||
force: true
|
force: true
|
||||||
when: skip_fetch | bool != true
|
when: skip_fetch | bool != true
|
||||||
|
@ -9,75 +9,42 @@
|
||||||
- name: Git clean
|
- name: Git clean
|
||||||
command: "git clean -fdx"
|
command: "git clean -fdx"
|
||||||
args:
|
args:
|
||||||
chdir: "blockscout-{{ group_names[0] }}-{{ chain }}"
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}"
|
||||||
when: skip_fetch | bool != true
|
when: skip_fetch | bool != true
|
||||||
|
|
||||||
- name: Merge branches
|
- name: Merge branches
|
||||||
command: "git merge {{ merge_commit_item }}"
|
command: "git merge {{ merge_commit_item }}"
|
||||||
args:
|
args:
|
||||||
chdir: "blockscout-{{ group_names[0] }}-{{ chain }}"
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}"
|
||||||
when: merge_commit_item and not skip_fetch | bool
|
when: merge_commit_item and not skip_fetch | bool
|
||||||
vars:
|
vars:
|
||||||
merge_commit_item: "{{ merge_commit | default(false) }}"
|
merge_commit_item: "{{ merge_commit | default(false) }}"
|
||||||
|
|
||||||
- name: Copy web config files
|
- name: Copy web config files
|
||||||
copy:
|
copy:
|
||||||
src: "blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/config/dev.secret.exs.example"
|
src: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/config/dev.secret.exs.example"
|
||||||
dest: "blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/config/dev.secret.exs"
|
dest: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/config/prod.secret.exs"
|
||||||
|
|
||||||
- name: Template explorer config files
|
- name: Template explorer config files
|
||||||
template:
|
template:
|
||||||
src: dev.secret.exs.j2
|
src: dev.secret.exs.j2
|
||||||
dest: "blockscout-{{ group_names[0] }}-{{ chain }}/apps/explorer/config/dev.secret.exs"
|
dest: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/explorer/config/prod.secret.exs"
|
||||||
when: ps_user is defined
|
when: ps_user is defined
|
||||||
|
|
||||||
- name: Copy default explorer config files
|
- name: Copy default explorer config files
|
||||||
copy:
|
copy:
|
||||||
src: "blockscout-{{ group_names[0] }}-{{ chain }}/apps/explorer/config/dev.secret.exs.example"
|
src: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/explorer/config/dev.secret.exs.example"
|
||||||
dest: "blockscout-{{ group_names[0] }}-{{ chain }}/apps/explorer/config/dev.secret.exs"
|
dest: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/explorer/config/prod.secret.exs"
|
||||||
when: ps_user is undefined or ps_user == ""
|
when: ps_user is undefined or ps_user == ""
|
||||||
|
|
||||||
- name: Remove static assets from previous deployment, if any
|
- name: Remove static assets from previous deployment, if any
|
||||||
file:
|
file:
|
||||||
path: "blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/priv/static"
|
path: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/priv/static"
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- name: Compile BlockScout
|
|
||||||
command: "mix do {{ item }}"
|
|
||||||
args:
|
|
||||||
chdir: "blockscout-{{ group_names[0] }}-{{ chain }}"
|
|
||||||
with_items:
|
|
||||||
- deps.get
|
|
||||||
- local.rebar --force
|
|
||||||
- deps.compile
|
|
||||||
- compile
|
|
||||||
- ecto.drop
|
|
||||||
- ecto.create
|
|
||||||
- ecto.migrate
|
|
||||||
|
|
||||||
- name: Install Node modules at apps/block_scout_web/assets
|
|
||||||
command: npm install
|
|
||||||
args:
|
|
||||||
chdir: "blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/assets"
|
|
||||||
|
|
||||||
- name: Execute webpack.js at apps/block_scout_web/assets/node_modules/webpack/bin
|
|
||||||
command: node_modules/webpack/bin/webpack.js --mode production
|
|
||||||
args:
|
|
||||||
chdir: "blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/assets"
|
|
||||||
|
|
||||||
- name: Instal Node modules at apps/explorer
|
|
||||||
command: npm install
|
|
||||||
args:
|
|
||||||
chdir: "blockscout-{{ group_names[0] }}-{{ chain }}/apps/explorer"
|
|
||||||
|
|
||||||
- name: Install SSL certificates
|
|
||||||
command: mix phx.gen.cert blockscout blockscout.local
|
|
||||||
args:
|
|
||||||
chdir: "blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web"
|
|
||||||
|
|
||||||
- name: Fetch environment variables (via access key)
|
- name: Fetch environment variables (via access key)
|
||||||
set_fact:
|
set_fact:
|
||||||
env: "{{ lookup('aws_ssm', path, aws_access_key=aws_access_key, aws_secret_key=aws_secret_key, region=aws_region|default('us-east-1'), shortnames=true, bypath=true, recursive=true ) }}"
|
env_compiled: "{{ lookup('aws_ssm', path, aws_access_key=aws_access_key, aws_secret_key=aws_secret_key, region=aws_region|default('us-east-1'), shortnames=true, bypath=true, recursive=true ) }}"
|
||||||
vars:
|
vars:
|
||||||
path: "/{{ group_names[0] }}/{{ chain }}"
|
path: "/{{ group_names[0] }}/{{ chain }}"
|
||||||
when: aws_access_key is defined
|
when: aws_access_key is defined
|
||||||
|
@ -100,7 +67,7 @@
|
||||||
|
|
||||||
- name: Override env variables
|
- name: Override env variables
|
||||||
set_fact:
|
set_fact:
|
||||||
env_compiled: "{{ env_compilated | combine(lower_env) }}"
|
env_compiled: "{{ env_compiled | combine(lower_env) }}"
|
||||||
when: lower_env is defined
|
when: lower_env is defined
|
||||||
|
|
||||||
- name: Uppercase chain
|
- name: Uppercase chain
|
||||||
|
@ -110,19 +77,59 @@
|
||||||
vars:
|
vars:
|
||||||
upper_env: {}
|
upper_env: {}
|
||||||
|
|
||||||
|
- name: Add server port
|
||||||
|
set_fact:
|
||||||
|
server_port: "{{ 65535|random(seed=inventory_hostname,start=1024) }}"
|
||||||
|
|
||||||
|
- name: Combine server env
|
||||||
|
set_fact:
|
||||||
|
server_env: "{{ upper_env | combine({'NETWORK_PATH':'/','PORT':server_port,'MIX_ENV':'prod','DATABASE_URL':'postgresql://' ~ ps_user ~ ':' ~ ps_password ~ '@' ~ ps_host ~ ':5432/' ~ ps_db}) }}"
|
||||||
|
|
||||||
|
- name: Compile BlockScout
|
||||||
|
command: "mix do {{ item }}"
|
||||||
|
args:
|
||||||
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}"
|
||||||
|
environment: "{{ server_env }}"
|
||||||
|
with_items:
|
||||||
|
- deps.get
|
||||||
|
- local.rebar --force
|
||||||
|
- deps.compile
|
||||||
|
- compile
|
||||||
|
- ecto.drop
|
||||||
|
- ecto.create
|
||||||
|
- ecto.migrate
|
||||||
|
|
||||||
|
- name: Install Node modules at apps/block_scout_web/assets
|
||||||
|
environment: "{{ server_env }}"
|
||||||
|
command: npm install
|
||||||
|
args:
|
||||||
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/assets"
|
||||||
|
|
||||||
|
- name: Execute webpack.js at apps/block_scout_web/assets/node_modules/webpack/bin
|
||||||
|
environment: "{{ server_env }}"
|
||||||
|
command: node_modules/webpack/bin/webpack.js --mode production
|
||||||
|
args:
|
||||||
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/assets"
|
||||||
|
|
||||||
|
- name: Instal Node modules at apps/explorer
|
||||||
|
environment: "{{ server_env }}"
|
||||||
|
command: npm install
|
||||||
|
args:
|
||||||
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/explorer"
|
||||||
|
|
||||||
|
- name: Install SSL certificates
|
||||||
|
environment: "{{ server_env }}"
|
||||||
|
command: mix phx.gen.cert blockscout blockscout.local
|
||||||
|
args:
|
||||||
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web"
|
||||||
|
|
||||||
- name: Start server
|
- name: Start server
|
||||||
block:
|
block:
|
||||||
- set_fact:
|
|
||||||
server_port: "{{ 65535|random(seed=inventory_hostname,start=1024) }}"
|
|
||||||
|
|
||||||
- set_fact:
|
|
||||||
server_env: "{{ upper_env | combine({'NETWORK_PATH':'/','PORT':server_port,'MIX_ENV':'prod'}) }}"
|
|
||||||
|
|
||||||
- name: Start server
|
- name: Start server
|
||||||
command: "mix phx.server"
|
command: "mix phx.server"
|
||||||
environment: "{{ server_env }}"
|
environment: "{{ server_env }}"
|
||||||
args:
|
args:
|
||||||
chdir: "blockscout-{{ group_names[0] }}-{{ chain }}"
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}"
|
||||||
async: 10000
|
async: 10000
|
||||||
poll: 0
|
poll: 0
|
||||||
|
|
||||||
|
@ -152,38 +159,42 @@
|
||||||
when: prompt is failed
|
when: prompt is failed
|
||||||
|
|
||||||
- name: Build static assets
|
- name: Build static assets
|
||||||
|
environment: "{{ server_env }}"
|
||||||
command: mix phx.digest
|
command: mix phx.digest
|
||||||
args:
|
args:
|
||||||
chdir: "blockscout-{{ group_names[0] }}-{{ chain }}"
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}"
|
||||||
|
|
||||||
- name: User prompt
|
- name: User prompt
|
||||||
pause:
|
pause:
|
||||||
prompt: "Would you like to remove staging dependencies? [Yes/No] Default: Yes"
|
prompt: "Would you like to remove staging dependencies? [Yes/No] Default: Yes"
|
||||||
register: user_answer
|
register: user_answer
|
||||||
until: user_answer.user_input|lower != "false" and user_answer.user_input|lower != "no" and user_answer.user_input|lower != "true" and user_answer.user_input|lower != "yes"
|
until: user_answer.user_input | lower in conditional
|
||||||
retries: 10000
|
retries: 10000
|
||||||
delay: 1
|
delay: 1
|
||||||
|
vars:
|
||||||
|
conditional: ['yes','no','true','false']
|
||||||
|
when: inventory_hostname == groups['all'][0]
|
||||||
|
|
||||||
- name: Remove dev dependencies
|
- name: Remove dev dependencies
|
||||||
file:
|
file:
|
||||||
state: absent
|
state: absent
|
||||||
path: "{{ item }}"
|
path: "{{ item }}"
|
||||||
with_items:
|
with_items:
|
||||||
- "blockscout-{{ group_names[0] }}-{{ chain }}/_build/"
|
- "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/_build/"
|
||||||
- "blockscout-{{ group_names[0] }}-{{ chain }}/deps/"
|
- "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/deps/"
|
||||||
- "blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/assets/node_modules/"
|
- "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/assets/node_modules/"
|
||||||
- "blockscout-{{ group_names[0] }}-{{ chain }}/apps/explorer/node_modules/"
|
- "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/explorer/node_modules/"
|
||||||
- "blockscout-{{ group_names[0] }}-{{ chain }}/logs/dev/"
|
- "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/logs/dev/"
|
||||||
when: user_answer.user_input | lower | bool
|
when: hostvars[groups['all'][0]].user_answer.user_input | lower | bool
|
||||||
|
|
||||||
- name: Fix bug with favicon
|
- name: Fix bug with favicon
|
||||||
replace:
|
replace:
|
||||||
regexp: '\"favicon\.ico\"\:\"favicon-[a-z0-9]+?\.ico\"'
|
regexp: '\"favicon\.ico\"\:\"favicon-[a-z0-9]+?\.ico\"'
|
||||||
replace: '"images/favicon.ico":"favicon.ico"'
|
replace: '"images/favicon.ico":"favicon.ico"'
|
||||||
path: "blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/priv/static/cache_manifest.json"
|
path: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/priv/static/cache_manifest.json"
|
||||||
|
|
||||||
- name: Upload Blockscout to S3
|
- name: Upload Blockscout to S3
|
||||||
command: "{{ 'AWS_ACCESS_KEY='~aws_access_key~' AWS_SECRET_ACCESS_KEY='~aws_secret_key~' AWS_DEFAULT_REGION='~aws_region if aws_profile is undefined else '' }} aws deploy push --application-name={{ group_names[0] }}-explorer --s3-location s3://{{ group_names[0] }}-explorer-codedeploy-releases/blockscout-{{ group_names[0] }}-{{ chain }}.zip --source=blockscout-{{ group_names[0] }}-{{ chain }} {{ '--profile='~aws_profile if aws_profile is defined else '' }}"
|
command: "{{ 'AWS_ACCESS_KEY='~aws_access_key~' AWS_SECRET_ACCESS_KEY='~aws_secret_key~' AWS_DEFAULT_REGION='~aws_region if aws_profile is undefined else '' }} aws deploy push --application-name={{ group_names[0] }}-explorer --s3-location s3://{{ group_names[0] }}-explorer-codedeploy-releases/blockscout-{{ group_names[0] }}-{{ chain }}.zip --source=/tmp/blockscout-{{ group_names[0] }}-{{ chain }} {{ '--profile='~aws_profile if aws_profile is defined else '' }}"
|
||||||
register: push_output
|
register: push_output
|
||||||
|
|
||||||
- name: Upload output
|
- name: Upload output
|
||||||
|
@ -194,9 +205,12 @@
|
||||||
pause:
|
pause:
|
||||||
prompt: "Do you want to update the Parameter Store variables? [Yes/No] Default: Yes"
|
prompt: "Do you want to update the Parameter Store variables? [Yes/No] Default: Yes"
|
||||||
register: user_answer
|
register: user_answer
|
||||||
until: user_answer.user_input | lower != "false" and user_answer.user_input | lower != "no" and user_answer.user_input | lower != "true" and user_answer.user_input | lower != "yes"
|
until: user_answer.user_input | lower in conditional
|
||||||
retries: 10000
|
retries: 10000
|
||||||
delay: 1
|
delay: 1
|
||||||
|
vars:
|
||||||
|
conditional: ['yes','no','true','false']
|
||||||
|
when: inventory_hostname == groups['all'][0]
|
||||||
|
|
||||||
- name: Update chain variables
|
- name: Update chain variables
|
||||||
aws_ssm_parameter_store:
|
aws_ssm_parameter_store:
|
||||||
|
@ -212,16 +226,19 @@
|
||||||
profile: "{{ aws_profile|default(omit) }}"
|
profile: "{{ aws_profile|default(omit) }}"
|
||||||
region: "{{ aws_region|default(omit) }}"
|
region: "{{ aws_region|default(omit) }}"
|
||||||
with_dict: "{{ lower_env }}"
|
with_dict: "{{ lower_env }}"
|
||||||
when: user_answer.user_input | lower | bool
|
when: hostvars[groups['all'][0]].user_answer.user_input | lower | bool
|
||||||
|
|
||||||
- name: User prompt
|
- name: User prompt
|
||||||
pause:
|
pause:
|
||||||
prompt: "Do you want to deploy BlockScout? [Yes/No] Default: Yes"
|
prompt: "Do you want to deploy BlockScout? [Yes/No] Default: Yes"
|
||||||
register: user_answer
|
register: user_answer
|
||||||
until: user_answer.user_input | lower != "false" and user_answer.user_input | lower != "no" and user_answer.user_input | lower != "true" and user_answer.user_input | lower != "yes"
|
until: user_answer.user_input | lower in conditional
|
||||||
retries: 10000
|
retries: 10000
|
||||||
delay: 1
|
delay: 1
|
||||||
|
vars:
|
||||||
|
conditional: ['yes','no','true','false']
|
||||||
|
when: inventory_hostname == groups['all'][0]
|
||||||
|
|
||||||
- name: Deploy Blockscout
|
- name: Deploy Blockscout
|
||||||
command: "{{ 'AWS_ACCESS_KEY='~aws_access_key~' AWS_SECRET_ACCESS_KEY='~aws_secret_key~' AWS_DEFAULT_REGION='~aws_region if aws_profile is undefined else '' }} {{ push_output.stdout_lines[1] }} --deployment-group-name {{ group_names[0] }}-explorer-dg{{ groups[group_names[0]].index(inventory_hostname) }} --deployment-config-name CodeDeployDefault.OneAtATime --description '{{ env_compiled['BLOCKSCOUT_VERSION'] }}' {{ '--profile='~aws_profile if aws_profile is defined else '' }}"
|
command: "{{ 'AWS_ACCESS_KEY='~aws_access_key~' AWS_SECRET_ACCESS_KEY='~aws_secret_key~' AWS_DEFAULT_REGION='~aws_region if aws_profile is undefined else '' }} {{ push_output.stdout_lines[1] }} --deployment-group-name {{ group_names[0] }}-explorer-dg{{ groups[group_names[0]].index(inventory_hostname) }} --deployment-config-name CodeDeployDefault.OneAtATime {{ '--profile='~aws_profile if aws_profile is defined else '' }}"
|
||||||
when: user_answer.user_input | lower | bool
|
when: hostvars[groups['all'][0]].user_answer.user_input | lower | bool
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
- name: "Loop over config files"
|
- name: "Loop over config files"
|
||||||
include: subtasks.yml file={{item}}
|
include: config.yml file={{item}}
|
||||||
with_items:
|
with_items:
|
||||||
- "group_vars/all.yml"
|
- "group_vars/all.yml"
|
||||||
- "group_vars/{{ group_names[0] }}"
|
- "group_vars/{{ group_names[0] }}"
|
||||||
|
|
Loading…
Reference in New Issue