Run Anisble Playbook From Azure Devops Release Pipeline – DZone DevOps | xxxRun Anisble Playbook From Azure Devops Release Pipeline – DZone DevOps – xxx
菜单

Run Anisble Playbook From Azure Devops Release Pipeline – DZone DevOps

七月 18, 2020 - MorningStar

Over a million developers have joined DZone.

  • Run Anisble Playbook From Azure Devops Release Pipeline - DZone DevOps

    {{node.title}}

    {{node.type}} · {{ node.urlSource.name }} by

    Download {{node.downloads}}

  • {{totalResults}} search results

{{announcement.body}}

{{announcement.title}}

Let’s be friends:

= 1024)” dc-slot=”ads.sl1.slot(articles[0], 0)” tags=”ads.sl1.tags(articles[0], 0)” size=”ads.sl1.size(articles[0], 0)” style=”border:0;”>
1 && !articles[0].partner.isSponsoringArticle && (width >= 1024)” dc-slot=”ads.sb2.slot(articles[0], 0)” tags=”ads.sb2.tags(articles[0], 0)” size=”ads.sb2.size(articles[0], 0)”>

Run Anisble Playbook From Azure Devops Release Pipeline

DZone ‘s Guide to

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.

Aug. 24, 20 · DevOps Zone ·

Free Resource

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.

Run Anisble Playbook From Azure Devops Release Pipeline - DZone DevOps

Run Anisble Playbook From Azure Devops Release Pipeline - DZone DevOps

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.

Run Anisble Playbook From Azure Devops Release Pipeline - DZone DevOps

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

Run Anisble Playbook From Azure Devops Release Pipeline - DZone DevOps

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.

Run Anisble Playbook From Azure Devops Release Pipeline - DZone DevOps

Run Anisble Playbook From Azure Devops Release Pipeline - DZone DevOps

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

$(<reference name>.secureFilePath)

Ex: $(pemKey.SecureFilePath)

Run Anisble Playbook From Azure Devops Release Pipeline - DZone DevOps

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.

Run Anisble Playbook From Azure Devops Release Pipeline - DZone DevOps

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.

Run Anisble Playbook From Azure Devops Release Pipeline - DZone DevOps

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 Anisble Playbook From Azure Devops Release Pipeline - DZone DevOps

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

Run Anisble Playbook From Azure Devops Release Pipeline - DZone DevOps

Run Anisble Playbook From Azure Devops Release Pipeline - DZone DevOps

Run Anisble Playbook From Azure Devops Release Pipeline - DZone DevOps

We can see our Release completed successfully.

Run Anisble Playbook From Azure Devops Release Pipeline - DZone DevOps

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.

Like This Article? Read More From DZone

Topics:
ansible, ansible playbook, azure devops, devops, tutorial

Opinions expressed by DZone contributors are their own.

DevOps Partner Resources

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.linkDescription }}

{{ parent.urlSource.name }}

by

CORE

· {{ parent.articleDate | date:’MMM. dd, yyyy’ }} {{ parent.linkDate | date:’MMM. dd, yyyy’ }}


Notice: Undefined variable: canUpdate in /var/www/html/wordpress/wp-content/plugins/wp-autopost-pro/wp-autopost-function.php on line 51