DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Enterprise AI Trend Report: Gain insights on ethical AI, MLOps, generative AI, large language models, and much more.

2024 Cloud survey: Share your insights on microservices, containers, K8s, CI/CD, and DevOps (+ enter a $750 raffle!) for our Trend Reports.

PostgreSQL: Learn about the open-source RDBMS' advanced capabilities, core components, common commands and functions, and general DBA tasks.

AI Automation Essentials. Check out the latest Refcard on all things AI automation, including model training, data security, and more.

Related

  • DevOps Nirvana: Mastering the Azure Pipeline To Unleash Agility
  • Azure DevOps Pipeline for Oracle Integration Cloud
  • Kubernetes Deployment Using Azure DevOps
  • Using Azure DevOps Pipeline With Gopaddle for No-Code Kubernetes Deployments

Trending

  • Service Mesh Unleashed: A Riveting Dive Into the Istio Framework
  • API Appliance for Extreme Agility and Simplicity
  • Some Thoughts on Bad Programming Practices
  • DZone's Article Submission Guidelines
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. DevOps and CI/CD
  4. Run Ansible Playbook From Azure DevOps Release Pipeline

Run Ansible Playbook From Azure DevOps Release Pipeline

Learn how to run the Ansible Playbook from the Azure DevOps tool. This tutorial assumes that the Ansible utility is installed and enabled.

By 
Virendar Kumar user avatar
Virendar Kumar
·
Rob Gravelle user avatar
Rob Gravelle
·
Updated Jan. 26, 24 · Tutorial
Like (2)
Save
Tweet
Share
24.5K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, you will learn how to run Ansible Playbook from the Azure DevOps tool. By incorporating Ansible Playbooks into the Azure release pipeline, organizations can achieve streamlined and automated workflows, reducing manual intervention and minimizing the risk of errors. This enhances the efficiency of the release process, accelerates time-to-market, and ensures a standardized and reliable deployment of applications and infrastructure on the Azure platform.

What Is an Ansible Playbook?

An Ansible Playbook is a configuration management and automation tool to define and execute a series of tasks. It is particularly valuable in managing infrastructure as code, ensuring consistency and repeatability in the deployment and configuration of systems. In the context of Azure release pipelines, Ansible Playbooks play a crucial role in automating the deployment and configuration of resources within the Azure environment. They allow for the definition of tasks such as provisioning virtual machines, configuring networking, and installing software components.

This tutorial assumes that the Ansible utility is installed and enabled for your Project in Azure DevOps.

You can download and install the utility from this link, and get it enabled from your Azure DevOps Administrator.

Related: Learn how to schedule pipelines in Azure DevOps.

How to Run Ansible Playbook From Azure DevOps

Step 1: Create New Release Pipeline

Create a new release pipeline with an empty job.

Create a new Release pipeline with an empty job


Stage 1: 1 job, 0 task

Step 2: Add Artifacts in Release Pipeline Job

Next, add Azure DevOps in artifacts, as I am using the Azure repository to store our playbook and inventory file. I have already pushed the inventory file and tutorial.yml playbook in my Azure repo branch, ansible-tutorial.

Select your project, repo, and branch to add artifacts in your release pipeline.

Select your Project, Repo, and branch to add artifacts in your release pipeline

YAML
 




xxxxxxxxxx
1


 
1
#tutorial.yml
2
- hosts: "{{ host }}"
3
  tasks:
4
   - name: create a test file for ansible
5
     shell: touch /tmp/tutorail.yml



Add project and source fields

Step 3: Upload and Configure Secure Key in Stage 1 for Ansible-Playbook Authentication

Use the SSH key for authentication on my target machine. To pass the SSH key, I will upload it using the Download Secure file utility available.

Download Secure Utility

This is used for storing secure files in your release pipeline like SSH key, SSL certs, and CA certs. During execution, files are downloaded in a temp folder and their path can be accessed by calling the reference variable (shown below). These files are deleted as the release job is completed.

Add tasks: Download secure file


Upload file

Enter the reference name as shown below. To access the file, use the variable $(<reference name>.secureFilePath).

  • Ex: $(pemKey.SecureFilePath)

Download secure file

Step 4: Change File Permission

We will add a shell command-line utility to change the file permission to 400 before using it in the playbook.

I have used $(pemKey.secureFilePath) to access the SSH key.

Change pem key permission

Step 5: Add and Configure the Ansible Task

Add the Ansible task and enter the playbook path as shown below. For an inventory, the location selects the file and the file path as shown below.

Use additional parameters to pass a variable to the Ansible playbook.

File path: This setting is required

Use additional parameters to pass variables and other command line parameters to the playbook at run time.

To pass the path of the SSH key, I have used ansible_ssh_private_key_file=$(pemKey.secureFilePath). 

Also, you can use the variable ansible_ssh_common_args='-o StrictHostKeyChecking=no' to disable the host key checking in your Ansible playbook, if it's failing due to a host key verification error.

Additional parameters

Step 6: Save the Release Pipeline and Create a Release To Run the Playbook

New release pipeline: Create a release/no releases found


Create a new release: Stage 1


New release pipeline

We can see our release completed successfully.

Release completed successfully

Summary

Ansible playbook ran successfully from Azure DevOps. If you want to use a username and password instead of an SSH key, you can pass the Linux creds using additional parameters using secrets variables so that the creds will be masked, or you can also use a shell command-line utility to set creds in an environment variable and Ansible will read from there.

azure Pipeline (software) DevOps Ansible (software)

Opinions expressed by DZone contributors are their own.

Related

  • DevOps Nirvana: Mastering the Azure Pipeline To Unleash Agility
  • Azure DevOps Pipeline for Oracle Integration Cloud
  • Kubernetes Deployment Using Azure DevOps
  • Using Azure DevOps Pipeline With Gopaddle for No-Code Kubernetes Deployments

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: