-
Notifications
You must be signed in to change notification settings - Fork 350
/
keyvault_create.yml
88 lines (80 loc) · 2.35 KB
/
keyvault_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
# Description
# ===========
# This playbook create a Key Vault , then add key and secret in it.
# This playbook requires Ansible version >= 2.5, and azure_preview_modules role
# You need to run "ansible-galaxy install azure.azure_preview_modules" to install the role to get lastest Ansible modules.
---
- hosts: localhost
tasks:
- name: Prepare random postfix
set_fact:
rpfx: "{{ 10000 | random }}"
run_once: yes
- hosts: localhost
# roles:
# - azure.azure_preview_modules
vars:
resource_group: "{{ resource_group_name }}"
location: eastus
keyvault_name: keyvault{{ rpfx }}
roles:
- azure.azure_preview_modules
tasks:
- name: set facts
set_fact:
object_id: "{{ lookup('env', 'AZURE_OBJECT_ID') }}"
- name: Create a resource group
azure_rm_resourcegroup:
name: "{{ resource_group }}"
location: "{{ location }}"
- name: Create instance of Key Vault
azure_rm_keyvault:
resource_group: "{{ resource_group }}"
vault_name: "{{ keyvault_name }}"
vault_tenant: "{{ azure_tenant }}"
enabled_for_deployment: yes
sku:
name: standard
family: A
access_policies:
- object_id: "{{ object_id }}"
keys:
- get
- list
- update
- create
- import
- delete
- recover
- backup
- restore
secrets:
- get
- list
- set
- delete
- recover
- backup
- restore
- name: create a kevyault key
block:
- azure_rm_keyvaultkey:
keyvault_uri: https://{{ keyvault_name }}.vault.azure.net
key_name: testkey
tags:
testing: test
delete: on-exit
register: output
- assert:
that: output.changed
rescue:
- azure_rm_keyvaultkey:
keyvault_uri: https://{{ keyvault_name }}.vault.azure.net
state: absent
key_name: testkey
- name: create a kevyault secret
block:
- azure_rm_keyvaultsecret:
keyvault_uri: https://{{ keyvault_name }}.vault.azure.net
secret_name: testsecret
secret_value: 'mysecret'