IBM Cloud Global

Cloud Global

Our mission is to provide clients with an online user community of industry peers and IBM experts, to exchange tips and tricks, best practices, and product knowledge. We hope the information you find here helps you maximize the value of your IBM Cloud solutions.

 View Only

Use Ansible for Day 1 and Day 2 Automation of IBM cloud Classic VSI

By Vineesh V posted Tue May 21, 2024 11:39 PM

  

Automation is a way of creating an application process that will help to plan and execute some set of repetitive tasks with minimal human interference or without any human interference. Ansible is an opensource automation tool developed in Python. It can configure systems, deploy software, and orchestrate many advanced applications and system managing workflows.

Ansible's main strengths are, it is simple to use in human-readable language format and unlike some other automation tools, Ansible operates in an agentless easy manner, leveraging OpenSSH secure transport protocol for managing servers. Ansible supports a wide range of operating systems and platforms, including Linux, Windows, macOS, and various cloud environments. And from a security point view, Ansible offers best security practices like SSH key-based authentication, encrypted communication, and role-based access control (RBAC). Additionally, Ansible's auditability and traceability features support compliance with regulatory requirements and security standards.

Here we are discussing the use of IBM cloud ansible modules to automate Classic VSI servers Day1 and Day2 automation possibilities with some simple example's playbooks. Day 1 automation is deploying IBM Classic VSI servers with proper resources. IBM cloud Ansible modules "ibm_compute_vm_instance" will help you deploy Classic VSI server in your IBM account and make these VSI servers are connected to the ansible server to continue the Day2 activities. Day2 automation is mostly configuring Operating system configuration and deploying applications, we can split all these into different tasks.

Prerequisites:

1. We need an ansible server which is connect to internet or should be able to communicate with IBM cloud API server (api.softlayer.com) and cloud.ibm.com

2. Install Python3 and Ansible latest version. Check here

3. And you need IBM cloud API key and IBM Classic username and API keys. More details available in these documents:

3.1 Create IBM classic API key document3.2 Create IBM cloud API key document

4. Install IBM Ansible collection using below command.

# ansible-galaxy collection install ibm.cloudcollection

We can split all these automation requirements in different ansible tasks, please see the details below. Find the var.yml file below

In variable files, we define important variables for creating VSI servers and API details for connecting ansible playbook to IBM cloud classic environment.

Here we are copying the ansible server SSH public key to the VSI server while provisioning time, which will help continue running your second ansible play for DAY2 automation. So here I created Ansible playbook and task to create a new SSH key instance in IBM cloud classic if it is not existing.

This above task will create a SSH key instance in IBM classic with name "Ansible-control-server", You can check this https://cloud.ibm.com/gen1/infrastructure/ssh-keys

Second and third tasks will create a host group "[IBM_hosts]" in default inventory file and creating the VSI servers with help loop based of the configuration that defined in var.yml file.

DAY2 Automation: As the Ansible server SSH key is already deployed into the VSI servers during the provisioning, Ansible server can seamlessly connect all VSI servers, and we can do lots of tasks like OS customization, Application deployment, production checks etc with help of 1000+ ansible modules

Here I added some few tasks as an example for the DAY2 automation, we can add more Ansible task to this Ansible play based on environment requirements.

Play2

Full play Book available https://github.com/v2vineesh/IBMcloud-classic

Like we execute all other Ansible play books, you can call this play like below, And this deploy all VSI servers and other customization tasks from a single call

# ansible-playbook /path_to_the_playbook_file/Main.yml

Here is the output of some sample VSI server creation executed in test environment

Play book output

IBM customer cloud portal results:

0 comments
13 views

Permalink