-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9bdb555
commit d7663a0
Showing
2 changed files
with
49 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,54 @@ | ||
--- | ||
- name: Create GCP Cloud SQL Instance | ||
hosts: all | ||
gather_facts: false | ||
tasks: | ||
- name: Activate service account | ||
shell: 'gcloud auth activate-service-account --key-file {{ service_account_file }} --project {{ project }}' | ||
- name: Create GCP Cloud SQL Instance | ||
hosts: all | ||
gather_facts: false | ||
tasks: | ||
- name: Activate service account | ||
shell: gcloud auth activate-service-account --key-file {{ service_account_file }} --project {{ project }} | ||
args: | ||
executable: /usr/bin/bash | ||
|
||
# https://cloud.google.com/sql/docs/mysql/connect-instance-cloud-shell | ||
- name: Enable Cloud SQL Admin API | ||
shell: | | ||
GCP_SERVICE=sqladmin.googleapis.com | ||
GCP_SERVICE_ENABLED=$(gcloud services list --filter ${GCP_SERVICE} --format json --enabled | jq length) | ||
if [ ${GCP_SERVICE_ENABLED} == 0 ]; then | ||
gcloud services enable ${GCP_SERVICE} | ||
fi | ||
# https://cloud.google.com/sql/docs/mysql/connect-instance-cloud-shell | ||
- name: Enable Cloud SQL Admin API | ||
shell: | | ||
GCP_SERVICE=sqladmin.googleapis.com | ||
GCP_SERVICE_ENABLED=$(gcloud services list --filter ${GCP_SERVICE} --format json --enabled | jq length) | ||
if [ ${GCP_SERVICE_ENABLED} == 0 ]; then | ||
gcloud services enable ${GCP_SERVICE} | ||
fi | ||
args: | ||
executable: /usr/bin/bash | ||
|
||
# https://cloud.google.com/sql/docs/mysql/create-instance | ||
# https://cloud.google.com/sdk/gcloud/reference/sql/instances/create | ||
- name: Create Instance | ||
shell: 'gcloud sql instances create {{ instance_name }} --tier {{ instance_tier }} --region {{ region }} --database-version={{ database_version }} --authorized-networks {{ authorized_networks }} --availability-type {{ availability_type }} {{ "--backup --enable-bin-log" if backups else "--no-backup" }} --timeout unlimited' | ||
# https://cloud.google.com/sql/docs/mysql/create-instance | ||
# https://cloud.google.com/sdk/gcloud/reference/sql/instances/create | ||
- name: Create Instance | ||
shell: | | ||
gcloud sql instances create {{ instance_name }} \ | ||
--tier {{ instance_tier }} \ | ||
--region {{ region }} \ | ||
--database-version={{ database_version }} \ | ||
--authorized-networks {{ authorized_networks }} \ | ||
--availability-type {{ availability_type }} \ | ||
{{ "--backup --enable-bin-log" if backups else "--no-backup" }} \ | ||
--timeout unlimited | ||
args: | ||
executable: /usr/bin/bash | ||
|
||
# https://cloud.google.com/sql/docs/mysql/create-instance | ||
- name: Set Root Password | ||
shell: 'gcloud sql users set-password root --host=% --instance {{ instance_name }} --password {{ root_password }}' | ||
# https://cloud.google.com/sql/docs/mysql/create-instance | ||
- name: Set Root Password | ||
shell: gcloud sql users set-password root --host=% --instance {{ instance_name }} --password {{ root_password }} | ||
args: | ||
executable: /usr/bin/bash | ||
|
||
# https://cloud.google.com/sdk/gcloud/reference/sql/instances/describe | ||
- name: Get Instance Information | ||
shell: 'gcloud sql instances describe {{ instance_name }}' | ||
register: instance_info | ||
# https://cloud.google.com/sdk/gcloud/reference/sql/instances/describe | ||
- name: Get Instance Information | ||
shell: gcloud sql instances describe {{ instance_name }} | ||
register: instance_info | ||
args: | ||
executable: /usr/bin/bash | ||
|
||
- name: Set Attributes | ||
set_stats: | ||
data: | ||
public_address: '{{ (instance_info.stdout | from_yaml).ipAddresses[0].ipAddress }}' | ||
- name: Set Attributes | ||
set_stats: | ||
data: | ||
public_address: '{{ (instance_info.stdout | from_yaml).ipAddresses[0].ipAddress }}' |