About running Ansible playbook via azure pipeline on windows agent machine

Right now I just want to create topic and subscription for azure service bus via ansible from azure pipeline. My pipeline use windows based agent and I am able to install ansible but not able to run playbooks like create topic and subscription for azure service bus.

Also I am providing here my code.

trigger:
batch: true
branches:
include:
- main
paths:
include:
- Server.Modern
exclude:
- ‘Server.Modern/README.md’
- ‘Server.Modern/SETUP.md’
- ‘Server.Modern/.gitignore’

pool:
name: ‘NonProd-NEU’

variables:

  • group: REDACTED_VARIABLE_GROUP_1
  • group: REDACTED_VARIABLE_GROUP_2
  • group: REDACTED_VARIABLE_GROUP_3
  • group: REDACTED_VARIABLE_GROUP_4
  • group: REDACTED_VARIABLE_GROUP_5
  • template: ‘variables/variables-server-modern-qa.yml’
  • name: appName
    value: ‘server-modern’
  • name: dotnetVersion
    value: ‘10.x’

stages:

- stage: ‘TestAnsible’
displayName: ‘TEST: Ansible Service Bus Provisioning’

jobs:
- deployment: TestAnsibleJob
displayName: ‘Test Ansible Provisioning ONLY’
environment: ‘SC Server Modern QA’

  strategy:
    runOnce:
      deploy:
        steps:



          - script: echo "=== ANSIBLE TEST MODE - Service Bus Provisioning Only ==="
            displayName: 'TEST MODE Banner'



          - checkout: self
            displayName: 'Checkout source code'
            fetchDepth: 1



          - powershell: |
              Write-Host "Agent Name: $(Agent.Name)"
              Write-Host "Machine Name: $(Agent.MachineName)"
              Write-Host "Agent Version: $(Agent.Version)"
            displayName: 'Show Agent Information'



          - pwsh: |
              Write-Host "PowerShell Version:"
              $PSVersionTable.PSVersion
            displayName: 'Verify UTF8 Under PowerShell 7'



          - pwsh: |
              $env:PYTHONUTF8 = "1"
              $env:PYTHONIOENCODING = "utf-8"
            displayName: 'Verify UTF8 Environment Variables'



          - pwsh: |
              $env:PYTHONUTF8 = "1"
            displayName: 'Verify Python UTF8 Mode'



          - pwsh: |
              Write-Host "POWERSHELL DIAGNOSTICS"
              Write-Host "PYTHON DIAGNOSTICS"
              python --version
            displayName: 'Check PowerShell/Python/Ansible Diagnostics'



          - pwsh: |
              chcp 65001 | Out-Null



              $env:PYTHONUTF8 = "1"
              $env:PYTHONIOENCODING = "utf-8"



              $env:ANSIBLE_SKIP_CONFLICT_CHECK = "1"
              $env:ANSIBLE_FORCE_COLOR = "0"



              python --version



              python -m pip install --user --upgrade pip setuptools wheel --quiet
              python -m pip install --user ansible==10.6.0 --quiet



              python -m pip install --user azure-identity azure-core azure-mgmt-servicebus --quiet
            displayName: 'Setup Ansible (Sanitized)'



          - pwsh: |
              chcp 65001 | Out-Null



              $env:PYTHONUTF8 = "1"
              $env:PYTHONIOENCODING = "utf-8"



              $ansibleRoot = Join-Path "$(Build.SourcesDirectory)" "Infrastructure" "ansible"
              Set-Location $ansibleRoot



              function Invoke-Playbook {
                  param (
                      \[string\]$Playbook,
                      \[string\]$Inventory,
                      \[int\]$Retries = 2
                  )



                  for ($i = 1; $i -le $Retries; $i++) {



                      cmd /c "set PYTHONUTF8=1 && set PYTHONIOENCODING=utf-8 && python -X utf8 -m ansible.cli.playbook $Playbook -i $Inventory -v"



                      if ($LASTEXITCODE -eq 0) {
                          return
                      }
                  }



                  throw "Playbook failed: $Playbook"
              }



              $inventory = "inventories/qa.yml"



              Invoke-Playbook "playbooks/create-topics.yml" $inventory
              Invoke-Playbook "playbooks/create-subscriptions.yml" $inventory
              Invoke-Playbook "playbooks/create-queues.yml" $inventory
            displayName: 'Provision Service Bus (QA)'
            env:
              AZURE_SUBSCRIPTION_ID: $(AZURE_SUBSCRIPTION_ID)
              AZURE_CLIENT_ID: $(AZURE_CLIENT_ID)
              AZURE_CLIENT_SECRET: $(AZURE_CLIENT_SECRET)
              AZURE_TENANT_ID: $(AZURE_TENANT_ID)

          - script: echo "=== ANSIBLE TEST COMPLETE ==="
            displayName: 'TEST COMPLETE Banner'

ansible cannot be run from Windows. See the following link:

Here are two related posts that might be helpful, although the answer is basically the same as what @sivel already provided (at least natively it’s not possible on Windows):