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,575 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

+1 vote
1 answer

i have a pyhton code in my git/git repository how to build that code in jenkins

Follow these steps @Bhaskar: Step 1: Open the Jenkins ...READ MORE

answered Oct 14, 2019 in DevOps Tools by Kalgi
• 52,350 points
902 views
0 votes
1 answer

What are your favorite command-line tools for DevOps, and how do you use them in your daily workflows?

No DevOps working environment is possible without ...READ MORE

answered Oct 23 in DevOps Tools by Gagana
• 5,810 points
122 views
0 votes
0 answers

What tools do you use to automate compliance checks in DevOps workflows?

What tools do you use to automate ...READ MORE

Nov 3 in DevOps Tools by Anila
• 4,340 points
49 views
0 votes
1 answer

How do you keep documentation up to date with rapid changes in DevOps infrastructure?

DevOps processes and infrastructure are constantly evolving, ...READ MORE

answered Nov 18 in DevOps Tools by Gagana
• 5,810 points
45 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,053 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,530 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