2
votes

I am using Ansible for deployment of Google compute engine instances. I have a requirement to use Google Cloud SQL instance [MySQL], which is the managed database in Google-cloud solution.

Is there a way/module available in Ansible for creating and managing Google-cloud-Sql instance?

2
There's nothing in the docs and the development branch on Github isn't showing anything either so doesn't look like it.ydaetskcoR

2 Answers

3
votes

There's nothing in the docs and the development branch on Github isn't showing anything either so it doesn't look like there's a module available for your use right now.

One option is to simply shell out to do this with something like this:

- name: create google-cloud sql instance
  shell: >
    gcloud sql instances create \
      --activation-policy="{{ activation_policy }}" \
      --tier="{{ tier }}" \
      --pricing-plan="{{ pricing_plan }}" \
      --region="{{ region }}" \
      --gce-zone="{{ gce_zone }}" \
      --database-version="{{ mysql_version }}" \
      --backup-start-time= \
      "{{ instance_id }}"

Which is simply following the instructions in Google's docs for Google Cloud SQL.

Alternatively you could create the module yourself and raise a pull request on the Ansible core modules repo.

3
votes

Check Ansible 2.8/latest doc. There is a module for creating GCP CloudSQL instance & database:

TASK

- name: Create GCP CloudSQL instance
  gcp_sql_instance:
    name: '{{ sql_instance.name }}'
    backend_type: '{{ sql_instance.backend_type }}'
    database_version: '{{ sql_instance.database_version }}'
    settings:
      tier: '{{ sql_instance.tier }}'
    region: '{{ sql_instance.region }}'
    project: '{{ project_id }}'
    auth_kind: '{{ authentification_type }}'
    service_account_file: '{{ credentials_file }}'
    state: present

VARIABLES

### authentification
# authentification_type: application / machineaccount / serviceaccount
# service_account_file: "/path/to/auth.json"
project_id: []
authentification_type: serviceaccount
credentials_file: []

### Cloud_SQL instance specifications
# backend_type: FIRST_GEN / SECOND_GEN / EXTERNAL
# database_version: MYSQL_5_5 / MYSQL_5_6 / MYSQL_587 / POSTGRESQL_9_6
# tier: db-g1-smal / db-pg-g1-small / custom-2-2048
sql_instance:
  name: []
  backend_type: []
  database_version: []
  region: []
  tier: []