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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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
Partner Zones AWS Cloud
by AWS Developer Relations
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
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Database Integration Tests With Spring Boot and Testcontainers
  • Send Email Using Spring Boot (SMTP Integration)
  • Using OpenAI Embeddings Search With SingleStoreDB
  • Integration Testing Tutorial: A Comprehensive Guide With Examples And Best Practices

Trending

  • Database Integration Tests With Spring Boot and Testcontainers
  • Send Email Using Spring Boot (SMTP Integration)
  • Using OpenAI Embeddings Search With SingleStoreDB
  • Integration Testing Tutorial: A Comprehensive Guide With Examples And Best Practices
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. DevOps and CI/CD
  4. Run Anisble Playbook From Azure Devops Release Pipeline

Run Anisble Playbook From Azure Devops Release Pipeline

In this article, I will explain how to run Ansible Playbook from the Azure DevOps tool. This tutorial assumes that the Ansible utility is installed and enabled.

Virendar Kumar user avatar by
Virendar Kumar
·
Aug. 24, 20 · Tutorial
Like (2)
Save
Tweet
Share
19.47K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, I will explain how to run Ansible Playbook from the Azure DevOps tool.

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 the below link:

https://marketplace.visualstudio.com/items?itemName=ms-vscs-rm.vss-services-ansible 

And get it enabled from your Azure DevOps Administrator.

1) Create New Release Pipeline

I am creating a new Release pipeline with an empty job.


2) Add Artifacts in Release Pipeline Job

I am adding Azure DevOps in artifacts as I am using 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.

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





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

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

Download Secure Utility: Is used for storing secure files in your release pipeline like ssh key, SSL certs, 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.

new release pipeline

new release pipeline

Enter the reference name as shown below. To access the file use variable.

$(<reference name>.secureFilePath)

Ex: $(pemKey.SecureFilePath)

new release piprlinr

4) Change File Permission

We will add 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.

new release pipeline

5) Add and Configure the Ansible Task

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

Use additional parameters to pass a variable to Ansible playbook.

ansible playbook

Use Additional parameters to pass variable and other command line parameters to playbook at run time.

To pass the path of ssh key i have used  ansible_ssh_private_key_file=$(pemKey.secureFilePath) 

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

run playbook

6) Save the Release Pipeline and Create a Release To Run the Playbook

no release found

create a new release

new release pipeline

We can see our Release completed successfully.

Summary

Ansible playbook ran successfully from Azure DevOps. If you want to use username and password instead of 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.

Release (agency) azure Pipeline (software) DevOps

Opinions expressed by DZone contributors are their own.

Trending

  • Database Integration Tests With Spring Boot and Testcontainers
  • Send Email Using Spring Boot (SMTP Integration)
  • Using OpenAI Embeddings Search With SingleStoreDB
  • Integration Testing Tutorial: A Comprehensive Guide With Examples And Best Practices

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: