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:
1---
2- hosts: localhost
3 gather_facts: no
4 vars:
5 subscriptionId: "[REPLACE WITH YOUR OWN VALUES]"
6 az_client_id: "[REPLACE WITH YOUR OWN VALUES]"
7 az_tenant: "[REPLACE WITH YOUR OWN VALUES]"
8 az_secret: "[REPLACE WITH YOUR OWN VALUES]"
9 region: "westeurope"
10 publisher: "paloaltonetworks"
11 offer: "vmseries1"
12 sku: "bundle1"
13 tasks:
14 - name: Get Agreements for given Image parameters
15 azure_rm_resource:
16 subscription_id: "{{ subscriptionId }}"
17 client_id: "{{ az_client_id }}"
18 tenant: "{{ az_tenant }}"
19 secret: "{{ az_secret }}"
20 url: "https://management.azure.com/subscriptions/{{ subscriptionId }}/providers/Microsoft.MarketplaceOrdering/offerTypes/virtualmachine/publishers/{{ publisher }}/offers/{{ offer }}/plans/{{ sku }}/agreements/current?api-version=2015-06-01"
21 method: GET
22 api_version: "2015-06-01"
23 register: agreement_result
24
25 - name: Register Agreement properties as fact
26 set_fact:
27 agreement: "{{ agreement_result.response.properties }}"
28
29 - name: Accept Terms for given Image parameters
30 azure_rm_resource:
31 subscription_id: "{{ subscriptionId }}"
32 client_id: "{{ az_client_id }}"
33 tenant: "{{ az_tenant }}"
34 secret: "{{ az_secret }}"
35 url: "https://management.azure.com/subscriptions/{{ subscriptionId }}/providers/Microsoft.MarketplaceOrdering/offerTypes/virtualmachine/publishers/{{ publisher }}/offers/{{ offer }}/plans/{{ sku }}/agreements/current?api-version=2015-06-01"
36 method: PUT
37 api_version: "2015-06-01"
38 body:
39 properties:
40 publisher: "{{agreement.publisher}}"
41 product: "{{agreement.product}}"
42 plan: "{{agreement.plan}}"
43 licenseTextLink: "{{agreement.licenseTextLink}}"
44 privacyPolicyLink: "{{agreement.privacyPolicyLink}}"
45 retrieveDatetime: "{{agreement.retrieveDatetime}}"
46 signature: "{{agreement.signature}}"
47 accepted: "true"
48 register: result
49
50 - name: Accept Terms output
51 debug:
52 msg: "{{result}}"
Hope it helps!
Comments