
{"id":7409,"date":"2020-08-01T11:39:58","date_gmt":"2020-08-01T11:39:58","guid":{"rendered":"https:\/\/rax-stg-wp-aws.com\/blogs\/orchestrate-a-gcp-cloud-sql-instance\/"},"modified":"2026-11-03T19:28:39","modified_gmt":"2026-11-03T19:28:39","slug":"orchestrate-a-gcp-cloud-sql-instance","status":"publish","type":"blogs","link":"https:\/\/www.rackspace.com\/en-gb\/blogs\/orchestrate-a-gcp-cloud-sql-instance\/","title":{"rendered":"Orchestrate a GCP Cloud SQL instance"},"content":{"rendered":"<p>This blog post discusses how you can automate the creation of a Google\u00ae Cloud&nbsp;Platform (GCP) Cloud SQL instance by using Ansible\u00ae and Jenkins\u00ae. The blog also&nbsp;includes an example of spinning up a MySQL\u00ae Cloud SQL instance, version 5.7,<br \/>\nwith an Ansible playbook.<\/p>\n<p>Ansible and Jenkins let you spin up a GCP Cloud SQL instance quickly by&nbsp;accessing Cloud SQL with a project-specific GCP account. This option ensures&nbsp;additional security by providing access to the GCP console only to users with&nbsp;GCP admin access. You can write playbooks for different GCP services and roll out&nbsp;Jenkins jobs to users to spin up GCP infrastructure as needed.<\/p>\n<p><strong>Necessary tools<\/strong><\/p>\n<p>To perform this task, you need to use Ansible and Jenkins.<\/p>\n<p class=\"text-align-justify\"><strong>Ansible &#8211;&nbsp;<\/strong>Use this for configuration management and as an orchestration tool in DevOps. Ansible has a wide variety of prebuilt modules written in Python for different products in the market that you can customize by using Python.<\/p>\n<p class=\"text-align-justify\"><strong>Jenkins &#8211;&nbsp;<\/strong>You can use Jenkins as a continuous integration server or as an automation server. Based on Java\u00ae, Jenkins has a wide range of plug-ins for<br \/>\ndifferent products. You can customize the plug-ins by using Java or Apache\u00ae Groovy.<\/p>\n<p><strong>Prerequisites<\/strong><\/p>\n<p>In this task, Ansible acts as an orchestration tool, and Jenkins acts as an automation server. Prerequisites for doing this task include the following items:<\/p>\n<ol>\n<li>Install Jenkins and Ansible, accessible over the Internet, on the server.<\/li>\n<li>Create a service account, assign a Cloud SQL Admin role to the service&nbsp;account, and download the key of the service account.<\/li>\n<li>After you create the service account, enable the Cloud SQL Admin API for the&nbsp;project in which you created the service account. Find the URL <a href=\"https:\/\/console.developers.google.com\/apis\/api\/sqladmin.googleapis.com\/overview?project= &quot;Project ID&quot;\">here<\/a> for enabling&nbsp;the service account by using the following syntax.<\/li>\n<li>Use the following commands, as the `root` user, to install the required packages on the Ansible Server:<\/li>\n<\/ol>\n<p><em>&nbsp; &nbsp; &nbsp; &nbsp; yum install python-pip<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; pip install apache-libcloud<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; pip install google-auth<\/em><\/p>\n<p><strong>Set up the Ansible playbook<\/strong><br \/>\nAfter completing the prerequisites, you need to move the Ansible playbook and service account key file to the Jenkins server.<\/p>\n<p><strong>Ansible playbook<\/strong><\/p>\n<p>An Ansible playbook contains a set of instructions written in YAML. This example&nbsp;uses a gcp\\_sql\\_instance module to spin up the Cloud SQL instance. The&nbsp;following playbook creates a GCP Cloud SQL instance of MySQL database version 5.7:<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26412-body-Picture6_10.png\" alt=\"ansible gcp pic 6\" \/><\/p>\n<p>The playbook in this example uses the following playbook variables files and<br \/>\nstores them in <strong>vars.yml<\/strong>:&nbsp;<\/p>\n<p>\n&#8211; &nbsp;project\\_id: cloudsql-258106<br \/>\n&#8211; &nbsp;authentification\\_type: serviceaccount<br \/>\n&#8211; &nbsp;credentials\\_file: \/ansible-play\/cloudsql-auth.json<br \/>\n&#8211; &nbsp;instance\\_name: cloudsql-instance-mysql<br \/>\n&#8211; &nbsp;db\\_version: MYSQL\\_5\\_7<br \/>\n&#8211; &nbsp;gcp\\_region: us-central1<br \/>\n&#8211; &nbsp;instance\\_tier: db-n1-standard-1<\/p>\n<p><strong>Jenkins server<\/strong><\/p>\n<p>Jenkins is an automation server, and the job is a basic component in Jenkins&nbsp;that you use to define the task that you want to automate.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26412-body-Picture1_27.png\" alt=\"ansible gcp pic 1\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>The job defines <em>CloudSQL<\/em> as the job name.&nbsp;<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26412-body-Picture2_21.png\" alt=\"annsible gcp pic 2\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Ansible plug-in in Jenkins&nbsp;<\/strong><\/p>\n<p>To run the playbook in a Jenkins job, you must install the Ansible plug-in in&nbsp;Jenkins. Then use that plug-in in the <strong>Build<\/strong>&nbsp;step of the Jenkins job to specify&nbsp;the playbook as shown in the preceding screenshot<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26412-body-Picture3_16.png\" alt=\"ansible gcp pic 3\" \/><\/p>\n<p>After the CloudSQL job runs, you should see output similar to the following&nbsp;output:&nbsp;<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26412-body-Picture4_15.png\" alt=\"ansible gcp pic 4\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Jenkins user interface&nbsp;<\/strong><br \/>\nThe following screenshot shows the user interface (UI) in Jenkins that you use&nbsp;to run or make changes to the job. The screenshot shows the MySQL Cloud SQL&nbsp;instance created in GCP after Jenkins job completes:<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26412-body-Picture5_13.png\" alt=\"ansible gcp pic 5\" \/><\/p>\n<p><strong>Conclusion&nbsp;<\/strong><\/p>\n<p>Use Jenkins and Ansible to implement Infrastructure as a Code (IaaC), which&nbsp;helps to avoid human errors during infrastructure spin up and restricts access&nbsp;to the GCP console to a limited set of users. Automating this task by using&nbsp;Ansible and Jenkins provides a GUI for authorized Jenkins users who don&#8217;t know&nbsp;GCP or how to spin a Cloud SQL instance.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Orchestrate a GCP Cloud SQL instance<\/p>\n","protected":false},"author":2,"featured_media":7411,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","format":"standard","meta":{"content-type":"","nid":"26412","content_type":"blog","created_by":"10130","authored_on":"2023-12-21T12:39:58+00:00","field_article_industries":"","tag_category":"Technical","field_blog_author_text":"by  Dinesh Miriam, Oracle Database Administrator, Rackspace Technology","seo_description":"Data clean rooms in Snowflake and implementation of row access policies. Derive information without sharing details.\r\n","field_featured_image":"","insights_image":"\/wp-content\/uploads\/2026\/blog_technical_images\/26412-insights_image-productivity-technical-blog-1-insights.jpg","field_partners":"","rxt_platforms":"AWS Data","product":"","publisheddate":"2020-08-01T11:39:58","rxt_solutions":"Cloud, Cloud Adoption & Migration","opengraph_tag":"","x_tag":"","teaser_flag":"Technical Blog","seo_titile":"GCP Cloud SQL Instance | Rackspace Technology","field_topics":"","field_slug":"orchestrate-a-gcp-cloud-sql-instance","footnotes":""},"categories":[178],"tags":[204],"class_list":["post-7409","blogs","type-blogs","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-technical"],"_links":{"self":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/7409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs"}],"about":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/types\/blogs"}],"author":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/comments?post=7409"}],"version-history":[{"count":3,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/7409\/revisions"}],"predecessor-version":[{"id":9443,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/7409\/revisions\/9443"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/media\/7411"}],"wp:attachment":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/media?parent=7409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/categories?post=7409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/tags?post=7409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}