In this tutorial, you will use ** Ansible ** and ** Jenkins ** to deploy an image composed of Tomcat, ** Java **, and MySQL on ** Alibaba Cloud **.
Then, after setting up the master / slave (agent) environment of the Jenkins server, check the server status to make sure that the agent is running normally. Especially in my setup, I'm using the master node as the Jenkins server and the agent machine for Ansible. If you wish, you can have only one machine by installing Ansible on the master itself.
Then install Ansible Tool on the master and agent machines.
Introduce Ansible. Ansible is a powerful tool for IT automation that can be used in the CI / CD process to provision a target environment and deploy applications on it. However, be aware that Ansible is cumbersome to maintain and will reuse scripts in the long run. This is useful if you want to perform the same task across different servers / environments from a centralized location where Ansible is installed. Ansible is completely agentless, so Chef and Puppet It has an advantage over other IaC (Infrastructure-as-Code) tools such as a2c65.11461447.0.0.53a46c64aNElRK). With Ansible, there is no need to install an agent on the client system and automation is done by SSH communication between the client and server. With hundreds of instances in a given region, all automation is easy. Ansible playbooks are written in YAML / YML languages.
When it comes to Ansible, the following knowledge is also required.
--Control node: The machine in charge of the server that Ansible is installed and manages. --Inventory: A file that defines the hosts and host groups on which commands, modules, and tasks in a playbook run. This file can be in one of many formats, depending on your Ansible environment and plugins. Used to create a project-specific inventory file in another location. --Playbook: Part of Ansible's configuration, deployment, orchestration language. You can describe the policy you want to apply to the remote system and the sequence of steps.
First, install the Ansible plugin on Jenkins. To do this, follow the steps below.
Note: Do not install Ansible Tower, which is not required for the current setup used in this tutorial.
After installing the Ansible plugin on Jenkins, the next step is to install Ansible on the Client / Agent machine.
The Alibaba Ansible module is updated frequently, so please refer to the [link] on GitHub (https://github.com/alibaba/alibaba.alicloud?spm=a2c65.11461447.0.0.53a46c64aNElRK) for the latest version. I recommend it.
--If you are using CentOS 7.4, this command is a good choice.
sudo yum check-update; sudo yum install -y gcc libffi-devel python-devel openssl-devel epel-release
sudo yum install -y python-pip python-wheel
--If you are using Ubuntu 16.04 LTS, use this command.
sudo apt-get update && sudo apt-get install -y libssl-dev libffi-dev python-dev python-pip
sudo pip install ansible
sudo pip install ansible_alicloud
sudo pip install ansible_alicloud_module_utils
I created an Ansible playbook script for provisioning Alibaba ECS here. You can fork the source code and change the value of the parameter to suit your environment.
alicloud_access_key: <Alibaba Access Key>
alicloud_secret_key: <Alibaba Secret Key>
alicloud_region: <Alibaba Region for your resource> e.g. - ap-south-1
alicloud_zone: <Alibaba Zone for your resource> e.g. ap-south-1a
password: <New VM Password>
image: "m-a2d4qmk8v2w9s5wmh0rw"
Note: I am importing images from Alibaba Application Stacks provided by Zhuyun. Please check here. It consists of Linux, Nginx, MySQL and Jdk-Tomcat (Nginx1.6-jdk1.7-tomcat7-mysql5.5-vsFTPd2.2.2).
Now it's time to generate the access key and secret. To do this, follow the steps below.
access key
and secret key
, go to Alibaba Cloud Console (https://account.alibabacloud.com/login/login.htm?spm=a2c65.11461447.0.0.53a46c64aNElRK) Then select Resource Access Management (RAM) from the product menu. and ʻAccessKeySecret
, which are the values of ʻalicloud_access_key and ʻalicloud_secret_key
in the playbook.Note: If you close the dialog box, the AccessKey information will no longer be available. Therefore, it is important to copy and save this information before closing the dialog box.
Note) 1.
#!/usr/bin/env bash
for region in $( aliyun ecs DescribeRegions | jq '.Regions.Region[].RegionId' )
do
echo $region
reg=$( echo $region | sed s/\"//g )
echo '---'
for zone in $( aliyun ecs DescribeZones --RegionId $reg | jq '.Zones.Zone[].ZoneId' | sort )
do
echo $zone
done
echo ''
done
alicloud_region: cn-beijing
alicloud_zone: cn-beijing-a
The image ID of each region is shown below (for Linux, Nginx, MySQL, Jdk-Tomcat images). Of course, you need to change the image ID depending on the region.
To create and deploy an Alibaba VM using a Jenkins job, follow these steps:
SCM: - Git Repository URL:-Changed parameters to GitHub link Example: https://github.com/nadaraj15/alibaba_ansible/ Credentials:-None (public repository, so store credentials in Jenkins if private) Branch specifier (blank for'any'):-* / master
sudo apt-get update (Optional)
sudo apt-get install -y libssl-dev libffi-dev python-dev python-pip (Optional)
sudo pip install ansible[azure]==2.7.0rc2 (Optional)
sudo apt-get install -y maven (Optional)
cd /usr/bin
sudo wget https://raw.githubusercontent.com/nadaraj15/alibaba_ansible/master/AliVM.yml
--Playbook path: --AliVM.yml (playbook name) --Inventory: --Select "Do not specify Inventory" --Credentials:-Select None (I've embedded the credentials in the deployment file so I can pass them as environment variables)
Note: If jenkins_home
is your location, the default path is set to / var / jenkins_home
. However, if you have a custom location, you can use that location instead.
sudo rm -rf /var/jenkins_home/workspaces/<workspace_name>
You have now deployed an instance with Tomcat, Java, and MySQL installed. If you enter the public IP address that corresponds to your browser, you can see that the Apache Tomcat page is running because the web server is exposed through port 80 of the VM's public IP.
1、https://www.alibabacloud.com/blog/ci%2Fcd-with-jenkins---part-1%3A-install-jenkins-on-ubuntu_593717 2、https://www.alibabacloud.com/blog/continuous-integration-with-jenkins-on-alibaba-cloud_594512 3、https://www.alibabacloud.com/blog/594449 4、https://github.com/alibaba/ansible-provider 5、https://mohitgoyal.co/2017/02/14/add-linux-slave-node-in-the-jenkins/ 6、https://marketplace.alibabacloud.com/products/56728001/Tomcat_Nginx_My_SQL_Stack_Package_on_Ubuntu-cmjj011399.html?innerSource=search#product-details
Recommended Posts