How to use Azure DevOps server TFS Predefined Variable in My Ansible Playbook

0 votes

In my playbook, I'd like to use the Azure DevOps Predefine Variable "$(Build.SourcesDirectory)":

Here's my  playbook:

---
- hosts: KBR_MTL361
  tasks:
   - name: copy file
     win_copy:
      src: D:\Web.config
      dest: $(Build.SourcesDirectory)

I'm using Azure DevOps Pipeline to run this ansible-playbook:

Pipeline Task in TFS

However, it isn't working.

Is there anyone out there that knows how to use the pipeline variable?

Feb 9, 2022 in DevOps Tools by Edureka
• 850 points
1,625 views

1 answer to this question.

0 votes

Simply add your variables to the azure-pipelines as additional args. This is what yml looks like:

 - task: Ansible@0
      inputs:
        ansibleInterface: 'agentMachine'
        playbookPathOnAgentMachine: 'ansible/tfs_playbooks/install_agent.yml'
        inventoriesAgentMachine: 'file'
        inventoryFileOnAgentMachine: 'hosts.yml'
        args: '--extra-vars "build_source_dir=$(Build.SourcesDirectory) AGENT_URL=$(AGENT_URL)"'

The variables in your playbook can then be accessed:

---
- hosts: localhost
  tasks:
  - name: show debug
    debug:
      msg: "Dir {{ build_source_dir }} agent url {{AGENT_URL}}"
answered Feb 9, 2022 by Bhavitha
• 1,000 points

Related Questions In DevOps Tools

0 votes
0 answers

How can I use the Azure DevOps Extension for Azure CLI in Azure DevOps Server environments?

How can I use the Azure DevOps ...READ MORE

Dec 6, 2024 in DevOps Tools by Anila
• 5,040 points
54 views
0 votes
1 answer

How can I check and update user permissions in Azure DevOps to avoid permission-related errors?

Role-based access control (RBAC) is the model ...READ MORE

answered Dec 5, 2024 in DevOps Tools by Gagana
• 7,690 points
72 views
0 votes
1 answer

How can I update pipelines and pull requests to reflect a renamed branch in Azure DevOps?

Refresh Pipelines: Navigate to Azure DevOps Pipelines. In the ...READ MORE

answered Dec 19, 2024 in DevOps Tools by Gagana
• 7,690 points
71 views
0 votes
1 answer

Are there any limitations to comparing commits in Azure DevOps, and how can they be addressed?

Indeed, there are certain restrictions on comparing ...READ MORE

answered Dec 6, 2024 in DevOps Tools by Gagana
• 7,690 points
61 views
0 votes
0 answers

Are Azure DevOps REST APIs language-agnostic, and how can I use them in different programming environments?

Are Azure DevOps REST APIs language-agnostic, and ...READ MORE

Dec 9, 2024 in DevOps Tools by Anila
• 5,040 points
47 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,101 views
+2 votes
1 answer
0 votes
1 answer

Find PAT scope using azure DevOps rest api

At this time, there is no way ...READ MORE

answered Feb 11, 2022 in DevOps Tools by Bhavitha
• 1,000 points
1,558 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP