forked from Azure-Samples/ansible-playbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cosmosdb_create.yml
92 lines (83 loc) · 2.72 KB
/
cosmosdb_create.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Description
# ===========
# This playbook creates an Cosmos DB Account and all the prerequisites.
# It requires Ansible 2.8. For earlier version of Ansible, run:
# ansible-galaxy install azure.azure_preview_modules" to install the role to get lastest Ansible modules.
# This samle will:
# 1. Create resource group
# 2. Create virtual network
# 3. Create subnet
# 4. Create CosmosDB account
# 5. Query and print CosmosDB account keys
# 6. Delete CosmosDB account
---
- hosts: localhost
tasks:
- name: Prepare random postfix
set_fact:
rpfx: "{{ 1000 | random }}"
run_once: yes
- hosts: localhost
# roles:
# - azure.azure_preview_modules
vars:
resource_group: "{{ resource_group_name }}"
location: eastus
vnet_name: myVirtualNetwork
subnet_name: mySubnet
cosmosdbaccount_name: cosmos{{ rpfx }}
tasks:
- name: Create a resource group
azure_rm_resourcegroup:
name: "{{ resource_group }}"
location: "{{ location }}"
- name: Create virtual network
azure_rm_virtualnetwork:
resource_group: "{{ resource_group }}"
name: "{{ vnet_name }}"
address_prefixes_cidr:
- 10.1.0.0/16
- 172.100.0.0/16
dns_servers:
- 127.0.0.1
- 127.0.0.3
- name: Add subnet
azure_rm_subnet:
name: "{{ subnet_name }}"
virtual_network_name: "{{ vnet_name }}"
resource_group: "{{ resource_group }}"
address_prefix_cidr: "10.1.0.0/24"
- name: Create instance of Cosmos DB Account
azure_rm_cosmosdbaccount:
resource_group: "{{ resource_group }}"
name: "{{ cosmosdbaccount_name }}"
location: eastus
kind: global_document_db
geo_rep_locations:
- name: eastus
failover_priority: 0
- name: westus
failover_priority: 1
database_account_offer_type: Standard
is_virtual_network_filter_enabled: yes
virtual_network_rules:
- subnet:
resource_group: "{{ resource_group }}"
virtual_network_name: "{{ vnet_name }}"
subnet_name: "{{ subnet_name }}"
ignore_missing_vnet_service_endpoint: yes
enable_automatic_failover: yes
- name: Get Cosmos DB Account facts with keys
azure_rm_cosmosdbaccount_facts:
resource_group: "{{ resource_group }}"
name: "{{ cosmosdbaccount_name }}"
retrieve_keys: all
register: output
- name: Display Cosmos DB Acccount facts output
debug:
var: output
- name: Delete instance of Cosmos DB Account
azure_rm_cosmosdbaccount:
resource_group: "{{ resource_group }}"
name: "{{ cosmosdbaccount_name }}"
state: absent