Accepting Azure Marketplace Terms with Ansible

by Carlos Mendible on 14 Aug 2018 » Azure, DevOps

Last May I wrote: Accepting Azure Marketplace Terms with Azure CLI and this time we’ll accomplish the same task with Ansible.

Turns out that Ansible 2.6 comes with a handy new module: azure_rm_resource which lets you create, update or delete any Azure resource using Azure REST API. So I decided to take it for a test drive with the “Accepting Terms” sample.

I’ve hard coded Palo Alto Networks offer for the following playbook but feel free to use another offer:

---
- hosts: localhost
  gather_facts: no
  vars:
    subscriptionId: "[REPLACE WITH YOUR OWN VALUES]"
    az_client_id: "[REPLACE WITH YOUR OWN VALUES]"
    az_tenant: "[REPLACE WITH YOUR OWN VALUES]"
    az_secret: "[REPLACE WITH YOUR OWN VALUES]"
    region: "westeurope"
    publisher: "paloaltonetworks"
    offer: "vmseries1"
    sku: "bundle1"
  tasks:
    - name: Get Agreements for given Image parameters
      azure_rm_resource:
        subscription_id: ""
        client_id: ""
        tenant: ""
        secret: ""
        url: "https://management.azure.com/subscriptions//providers/Microsoft.MarketplaceOrdering/offerTypes/virtualmachine/publishers//offers//plans//agreements/current?api-version=2015-06-01"
        method: GET
        api_version: "2015-06-01"
      register: agreement_result

    - name: Register Agreement properties as fact
      set_fact:
        agreement: ""

    - name: Accept Terms for given Image parameters
      azure_rm_resource:
        subscription_id: ""
        client_id: ""
        tenant: ""
        secret: ""
        url: "https://management.azure.com/subscriptions//providers/Microsoft.MarketplaceOrdering/offerTypes/virtualmachine/publishers//offers//plans//agreements/current?api-version=2015-06-01"
        method: PUT
        api_version: "2015-06-01"
        body:
          properties:
            publisher: ""
            product: ""
            plan: ""
            licenseTextLink: ""
            privacyPolicyLink: ""
            retrieveDatetime: ""
            signature: ""
            accepted: "true"
      register: result

    - name: Accept Terms output
      debug:
        msg: ""

Hope it helps!