How to connect Alibaba Cloud to Ansible
Technology in China has been growing and with the dawn of cloud computing. It is only becoming harder to keep up. Alibaba Cloud will be the alternative to AWS in China since it is a technology native to China. AWS is present in China but has limited functionality since Chinese laws forbidden AWS to use foreign infrastructure in China.
Alibaba Cloud will be the next big thing in China and it is best to understand it today if you want to grow your career on an international level.
Step 1: Creating an Alibaba Cloud Account
In this article, we will see how to launch an Alibaba Cloud Elastic Compute Service instance and manage it using Ansible. The first here is to create an Alibab Cloud account. Do not worry, it has free usage for some instances. Luckily, the process that we are going to follow today will ensure that nothing gets charged to your Debit Card.
Use this link to create an account and then verify it using your e-mail: Alibaba Cloud Account
Step 2: Launching an Alibaba Cloud Instance
The next step is to choose and launch an instance. Click on Elastic Compute Service in your Alibaba Cloud Console. Now, click on the ‘Create Instance’ option. Now you need to choose the Pay-As-You-Go option also will have to change your region from Mainland China to any other region since launching an Instance in Mainland China requires additional verification.
You can further change the instance type as per your requirements. For this tutorial, I am going with the default one. The next thing to do is to choose an image, for working with Ansible I’d recommend to go with CentOS 7.5 since it comes with Python 2.7 pre-installed.
The next section called Networking does not require any changes, so you can now move on forward to the next which is System Configurations. Here you need to create a new key-pair and download it to a secure location on your machine.
You can skip the grouping section as well, now you can finally launch your instance.
If you check your instances now, you will see that the instance we created is running.
Step 3: Connect Instance with SSH
The next step is to ensure that we are able to connect with this instance before linking it to Ansible. You can also ping it or directly SSH to it. Let us ping it before we try to SSH to the Alibaba Cloud Instance. In order to use ping or SSH, We will require the Public IP address or the IPv4 Public IP of the instance. Once you have the instance public IPV4 address, you can SSH or Ping it.
You should know that the ssh will only work if you also input your identity file. Without the identity file, you will get a permission denied error and will not be able to connect your instance.
Note: The username for all Alibaba Linux Cloud Instances is: root
ssh -i alibaba.pem publicIP
Step 4: Input Instance in Hosts File
Congratulations on having to successfully being able to SSH to an Alibaba Cloud instance. As you can imagine, the final step would be to input the instance details in the host or inventory file for Ansible and try to reach the instance through the Ansible ping module. When connecting with local machines, inputting the IP or the hostname of the remote machine in the Ansible hosts file is enough but in the case of Ansible, you will need to input some more information in order to successfully be able to connect to your Alibaba Cloud instance via Ansible.
The information you will need is:
• A name for your instance
• IP Address of your Alibaba Cloud instance
• The user present on your Alibaba Cloud instance
• Location to your private key (.pem) file
You will need to input the information somewhat like this in the hosts file:
alibaba-instance ansible_host=PublicIP ansible_user=root ansible_ssh_private_key_file=PrivateKeyLocation
Step 5: Run Ansible Ping Module
If you try running the ansible ping module now, you should receive an output like this:
Voila! You have successfully connected your machine to an Alibaba Cloud instance and can now manage it using Ansible. Try running basic Ansible modules like creating users and files.
Step 6: Terminate Alibaba Cloud Instance
Be sure to ‘Stop’ the Alibaba Cloud instance once you are done using it otherwise you could face some transactions on your bank account linked to the Alibaba Cloud account.
Why did I get ‘over and out’ instead of pong when I ran the ping module? I made some edits in the python file of my Ansible Module.
Looking to start a career in Red Hat Linux? Start with RHCSA & RHCE.
Linux Expert? Grow your career with AWS, Openstack or Openshift.