Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Deploy a job/script for automated patching in each GCP Project

what is the right approach to deploy a job/script for automated patching of VMs linked to a Project.

If we have 50-60 VMs in a Project and we have to schedule the Monthly patching . 

Do we need to deploy the script in a function or any other suggested way?

We are planning to use a single GCP service account for the same.

0 3 576
3 REPLIES 3

When it comes to deploying a job/script for automated patching of VMs in a project, there are multiple approaches you can consider. One option is to use a serverless approach like Google Cloud Functions. However, since you mentioned using a single Google Cloud Platform (GCP) service account for the task, a more suitable approach would be to use a configuration management tool like Ansible or Puppet.

Here's a suggested approach:

  1. Set up a centralized management server: Create a dedicated VM instance or use an existing one to serve as your management server. This server will be responsible for executing the patching script and managing the VMs.
  2. Install the necessary tools: Install the desired configuration management tool (e.g., Ansible or Puppet) on the management server. These tools will allow you to automate the patching process across multiple VMs.
  3. Define inventory: Create an inventory file that lists all the VMs you want to patch. This file can be in INI or YAML format and should contain the necessary details (such as IP addresses or hostnames) to connect to each VM.
  4. Write patching playbook/manifest: Create a playbook (in Ansible) or manifest (in Puppet) that describes the steps required to patch the VMs. This could include running system updates, installing security patches, and performing any necessary restarts.
  5. Configure the service account: Create a dedicated service account in GCP and grant it the necessary permissions to access and manage the VM instances. Make sure the service account has the required roles, such as compute.instanceAdmin or compute.osAdminLogin.
  6. Set up authentication: On the management server, configure authentication using the service account's credentials. This can involve setting up environment variables, key files, or other authentication mechanisms supported by your chosen configuration management tool.
  7. Schedule the job: Set up a cron job or a scheduled task on the management server to execute the patching script regularly. Choose a time that minimizes the impact on your VMs' availability and performance.
  8. Test and monitor: Before deploying the patching script to all VMs, test it on a smaller subset to ensure it works as expected. Monitor the patching process to detect any issues or failures and refine your script accordingly.

By following these steps, you can automate the patching process for your VMs in a controlled and scalable manner. Remember to keep your scripts and management server up to date with security patches to ensure the integrity of your patching infrastructure.

thank you Prabhakaranjm for detailed suggestion. I want to use google patch management(native patching solution) to patch the vms , using ansible/puppet , i think I need to write script based on os type . Google patch management automatically take cares of it .

My intension is to use google patch management solution using gcloud(commands) which reads the vms information from a storage bucket. and patch the vms mentioned in the Storage file.

so i would like to ask for this approach , which platform will be more suitable . function or any other where we can run the the patch jobs ( time limit more than 1 hour) including backup jobs before patching jobs . I want to create a workflow where one by one all these jobs gets triggered (backup --> patching).

Can you please suggest on this