This self-paced course will help you prepare for the Azure Developer certification exam AZ-204: Developing Solutions for Microsoft Azure.
Azure DevOps CICD with Ansible Infra Automation blog will help you understand how to use Ansible to create an Azure DevOps CICD pipeline. Ansible is an open-source tool that automates cloud provisioning, configuration management, and application deployments. Using Ansible you can provision virtual machines, containers, networks, and complete cloud infrastructures. In addition, Ansible allows you to automate the deployment and configuration of resources in your environment.
Users can also create their own modules. Modules can be used to control system resources — such as services, packages, or files — or execute system commands.
Ansible with Full CICD Workflow :
Things we are going to achieve in this lab scenarios are given below :
- Create an WebApp and the VM using Ansible Infra automation
- Provision the Azure DevOps Ansible Team Project with the Azure DevOps Demo Generator tool.
- Configure application and database deployment, using Continuous Deployment (CD) in the Azure DevOps
- Initiate the complete CICD process.
Steps to Implement the CICD process for AKS :
- Login to Azure DevOps Demo Generator using http://azuredevopsdemogenerator.azurewebsites.net/?TemplateId=77372&Name=AKS
- From the choose template option, we need to clone the Ansible and then click on Import.
3. Once after we import , we will be able to see the Azure DevOps project imported like below.
4. When we go to the Repositories , we will be able to see the code that we have imported to create a Website automation using ansible.
Steps to make the Azure Environment ready :
- Login to the Azure portal and open the cloud shell to run the commands to create the resources.
- Login to the cloud shell, and we need to create certain things that are shown below such as the service principal and VM’s.
az ad sp create-for-rbac — name AnsibleDemo
3. Once after the service principal is created , we can now create a VM for the ansible server .
4. Click Connect and copy the login command under the SSH tab.
5. Now we must create a directory named .azure in the home directory and a credentials file under it. Type the following commands to create them.
6. Now, we need ssh authentication using Ansible Control Machine private/public key pair. Now let us create a pair of private and public keys. Run the following command to generate a private/public key pair for ssh and to install the public key in the local machine.
ssh-keygen -t rsa
chmod 755 ~/.ssh
chmod 644 ~/.ssh/authorized_keys
ssh-copy-id [email protected]
7. We need SSH private key to created SSH endpoint in Azure DevOps service. Run the following command to get the private key. Copy the private key to notepad.
Steps to make the Azure DevOps CICD ready :
- Login to Azure Devops and then we need to go Project Settings –> Service Connections. Select +New service connection and select SSH
2. Next , we need to go to the repos and then change the ansible yaml file to give the details of the Azure resources.
After making these changes, try to commit the file and then start the CI pipeline .
3. Navigate to Pipeline » Releases. Select Ansible-CD and click Edit pipeline.
4. Under the Inventory section, select Host list as inventory location and enter pubic ip of your ansible vm in Host list field as shown below.
5. Select the Azure App Service Deploy task. Select the Azure subscription from the drop-down list and click Authorize to configure Azure service connection. And this application requires few app settings to connect to the MySQL database provisioned using Ansible script. That we are updating using the App settings parameter in the task.
Once the release is success navigate to your Azure portal. Search for smh360web in App services. Select the app that created with smh360-xxxx and browse to view the application deployed.
We can Login to the site with the following credentials.
Username: [email protected]