Search code examples
ansibleansible-tower

How to onboard a GCP project into Ansible Tower for running playbooks in it?


I have successfully used Ansible engine to provision GCP resources, using ansible playbooks with gcp module.

Now I am trying to do so using Ansible Tower, and I'm totally new to Ansible tower.

I am unable to understand how to create an inventory in Ansible Tower for the GCP. In tower, we can provide hosts where our yaml will run. How will I determine the host IP for GCP? Use cases:

  1. I want to provision a GCP compute engine .
  2. I want to provision a Bigquery dataset and tables.

What should be my host in ansible tower in both cases? Could someone please help?


Solution

  • Create a Credential to connect to GCP as below

    - Name: GCP Credentials
    - Description: GCP Credentials
    - Organization: Default
    - Credential Type: Google Compute Engine
    - Service Account Email Address: *This will be filled when upload json file*
    - Project: *This will be filled when upload json file*
    - Service Account Json File: yourfile.json
    - RSA Private Key: *This will be filled when upload json file*
    

    Create Inventory as below and save

    - Name: GCP Inventory
    - Description: GCP Inventory
    - Organization: Default
    

    Then, in Sources tab of Inventory click in the button of Create a new source with this information:

    - Name: GCP Source
    - Description: GCP Source
    - Source: Google Compute Engine
    - Credential: GCP Credentials
    

    In Sources tab of Inventory click the option "Start sync Process" of your new source. This will update your Hosts. With all this you just need to execute your playbook on localhost with a template using this credential and inventory.