Configuring Ansible in GCP

Tejas Jadhav
2 min readNov 8, 2023

--

Setting up Ansible in Google Cloud Platform (GCP) involves a few steps, including provisioning a virtual machine (VM) and ensuring Python is installed. Here’s a step-by-step approach to achieve this:

  1. Create a GCP Project (if not already done): If you don’t have a GCP project, create one by following the instructions on the GCP Console.
  2. Enable Compute Engine API: Ensure that the Compute Engine API is enabled for your GCP project. You can do this through the GCP Console:
  • Go to the GCP Console.
  • In the navigation menu, click on “APIs & Services” > “Library.”
  • Search for “Compute Engine API” and enable it.

3. Create a Virtual Machine Instance: Now, let’s create a VM instance in GCP where you’ll install Ansible.

  • In the GCP Console, go to “Compute Engine” > “VM instances.”
  • Click the “Create” button to create a new instance.
  • Fill in the necessary information, including the instance name, region, machine type, and other settings as per your requirements.

4. Set up a Firewall Rule (if necessary): If you plan to access the VM using SSH, make sure to create a firewall rule to allow SSH traffic. To create a firewall rule:

  • In the GCP Console, go to “VPC network” > “Firewall rules.”
  • Click the “Create Firewall Rule” button.
  • Configure the rule to allow SSH traffic (port 22) from your IP address or a range of IP addresses.

5. Install Ansible Prerequisites: SSH into your GCP VM and ensure that Python is installed. Most GCP VM images come with Python pre-installed. To SSH into your VM:

gcloud compute ssh [INSTANCE_NAME]

Replace [INSTANCE_NAME] with the name of your VM instance. Once connected, you can check if Python is installed by running:

python - version

If Python is not installed, you can install it by using the package manager available for your VM’s operating system.

6. Install Ansible: Once Python is confirmed to be available, you can install Ansible on your VM. The method to install Ansible depends on your VM’s operating system. Here’s how to do it for common Linux distributions:

For Debian/Ubuntu:

sudo apt-get update
sudo apt-get install ansible

For CentOS/RHEL:

sudo yum install epel-release
sudo yum install ansible

For other Linux distributions, you may need to follow the appropriate package manager’s commands to install Ansible.

7. Verify Ansible Installation: After installation, verify that Ansible is installed correctly by running:

ansible - version

You should see the Ansible version information.

--

--

Tejas Jadhav

Coding the future, one line at a time. Transforming challenges into opportunities and bugs into stepping stones. Let's build something extraordinary together.