-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaci.yml
65 lines (59 loc) · 2.03 KB
/
aci.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
# Description
# ===========
# This playbook creates below Azure resources:
# - Azure container Instance
#
# This playbook do:
# - git clone a hello world app.
# - build docker image of the app.
# - push the image to existing Azure Container Registry.
# - create Azure Container Instance, with image in Azure Container Registry pushed before.
#
- name: demo Build/Push docker image to Container Registry, Create Container Instance
hosts: localhost
vars:
resource_group: ansiblefest-yungez1
location: eastus
registry_name: acr0925
image_name: aci-helloworld
http_port: 80
repo_url: "https://github.com/Azure-Samples/aci-helloworld.git"
workspace: ~/src/aci-helloworld
roles:
- Azure.azure_preview_modules
tasks:
- name: Get existing Azure Container Registry facts
azure_rm_containerregistry_facts:
resource_group: "{{ resource_group }}"
name: "{{ registry_name }}"
retrieve_credentials: true
register: acr_result
- name: Git Clone
git:
repo: "{{ repo_url }}"
dest: "{{ workspace }}"
- name: Login docker registry
docker_login:
registry: "{{ registry_name }}.azurecr.io"
username: "{{ registry_name }}"
password: "{{ acr_result.registries[0].credentials.password }}"
- 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.registries[0].credentials.password }}"
containers:
- name: "{{ image_name }}"
ports:
- "{{ http_port }}"
image: "{{ registry_name }}.azurecr.io/{{ image_name }}"