forked from Azure-Samples/ansible-playbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aci_create_with_acr.yml
78 lines (76 loc) · 2.7 KB
/
aci_create_with_acr.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
# Description
# ===========
# This plabyook build a docker image, then push to azure container registry,
# then provision an azure container instance with that image.
# 1. clone a sample helloworld app
# 1. create azure container registery
# 1. build docker image from helloworld app, and push image to azure container azure container registry
# 1. create azure container instance with the image in azure container registry
#
# Prequisite
# ===========
# - git
# - Docker
- hosts: localhost
tasks:
- name: Prepare random postfix
set_fact:
rpfx: "{{ 1000 | random }}"
run_once: yes
- name: demo
hosts: localhost
# The modules of azure container registry and azure container instance are available since Ansible version 2.5.
# But if you are using Ansible version 2.4, you need to have below 2 lines to get modules of azure container registry and azure container instance from the playbook role of azure_preview_modules.
# roles:
# - azure.azure_preview_modules
vars:
resource_group: "{{ resource_group_name }}{{ rpfx }}"
location: eastus
registry_name: acr{{ rpfx }}
repo_url: "https://github.com/Azure-Samples/aci-helloworld.git"
workspace: ~/src/aci-helloworld
image_name: aci-helloworld
http_port: 80
email: [email protected]
tasks:
- name: Git Clone
git:
repo: "{{ repo_url }}"
dest: "{{ workspace }}"
- name: Create a resource group
azure_rm_resourcegroup:
name: "{{ resource_group }}"
location: "{{ location }}"
- name: Create Azure Container Registry
azure_rm_containerregistry:
resource_group: "{{ resource_group }}"
name: "{{ registry_name}}"
admin_user_enabled: True
sku: Standard
register: acr_result
- name: Login docker registry
docker_login:
registry: "{{ registry_name }}.azurecr.io"
username: "{{ registry_name }}"
password: "{{ acr_result.credentials.password }}"
email: "{{ email }}"
- name: Docker Build and Push
docker_image:
path: "{{ workspace }}"
name: "{{ registry_name }}.azurecr.io/{{ image_name }}"
push: yes
- name: Create Azure Container Instance
azure_rm_containerinstance:
resource_group: "{{ resource_group }}"
name: "{{ image_name }}"
ip_address: public
ports:
- "{{ http_port }}"
registry_login_server: "{{ registry_name }}.azurecr.io"
registry_username: "{{ registry_name }}"
registry_password: "{{ acr_result.credentials.password }}"
containers:
- name: "{{ image_name }}"
ports:
- "{{ http_port }}"
image: "{{ registry_name }}.azurecr.io/{{ image_name }}"