-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.yaml
137 lines (117 loc) · 3.73 KB
/
main.yaml
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---
- name: launch a compute instance
hosts: localhost
vars_files:
- vars.yaml
tasks:
- name: ssh security group
os_security_group:
state: present
name: ssh
description: allow SSH access on port 22
- name: add ssh rule
os_security_group_rule:
security_group: ssh
protocol: tcp
port_range_min: 22
port_range_max: 22
remote_ip_prefix: 0.0.0.0/0
- name: Create volume
os_volume:
display_name: "{{ volname }}"
size: "{{ volsize }}"
- name: launch an instance
os_server:
name: "{{ vmname }}"
state: present
image: "{{ image }}"
security_groups: ssh
flavor: "{{ flavor }}"
key_name: "{{ key_name }}"
nics:
- net-name: "{{ net_name }}"
volumes:
- "{{ volname }}"
wait: yes
register: osinstance
- name: Wait 15 seconds
pause: seconds=15
when: osinstance.changed
- name: Add new VM to ansible inventory
add_host:
name: imagebuilderansible
ansible_host: "{{ osinstance.server.public_v4 }}"
volume_device: "{{ osinstance.server.volumes[0].device }}"
ansible_user: "{{ ansible_user }}"
ansible_ssh_common_args: -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
- name: Configure imagebuilder host
vars:
- WEB_ROOT: /usr/share/nginx/html
- IMAGES_ROOT: "{{WEB_ROOT}}/images"
hosts: imagebuilderansible
tasks:
- name: install packages
become: True
apt: name={{item}} update_cache=yes
with_items:
- expect
- unattended-upgrades
- git
- qemu-utils
- qemu
- kpartx
- ntp
- debootstrap
- nginx
- screen
- htop
- python-pip
- python-setuptools
- python-dev
- name: pip upgrade
become: True
pip: name=pip state=latest executable=pip
- name: pip install python-keystoneclient
become: True
pip: name=python-keystoneclient
- name: pip install python-glanceclient
become: True
pip: name=python-glanceclient
- name: pip install networkx
become: True
pip: name=networkx version=1.11
- name: git clone SWITCH repo for diskimage-builder
git: repo=https://github.com/switch-ch/diskimage-builder.git dest=/home/ubuntu/diskimage-builder force=yes version=SWITCHengines
- name: Install diskimage-builder
become: True
shell: "cd /home/ubuntu/diskimage-builder ; python setup.py install"
- name: Check if images folder exists
stat: path='{{IMAGES_ROOT}}'
register: images_folder
- name: Format volume
become: True
filesystem: fstype=ext4 dev=/dev/vdb
when: images_folder.stat.exists == False
- name: Create web root for Nginx
become: True
file: path='{{IMAGES_ROOT}}' state=directory mode=0777
- name: Manage fstab
become: True
mount: name='{{IMAGES_ROOT}}' src=/dev/vdb fstype=ext4 state=mounted
when: images_folder.stat.exists == False
- name: Create nginx config
become: True
template: src=templates/default.j2 dest=/etc/nginx/sites-available/default
notify: restart nginx
- name: Create distrosInfo file in home dir
template: src=templates/distrosInfo.j2 dest=/home/ubuntu/distrosInfo
- name: Load the create images bash script
template: src=templates/SWITCHengines-create-images.sh.j2 dest=/home/ubuntu/SWITCHengines-create-images.sh mode="u=rwx,g=r,o=r"
- name: Load the python upload utility for images
copy: src=files/SWITCHengines-images-uploader.py dest=/home/ubuntu/SWITCHengines-images-uploader.py mode=0755
- name: Load the python upload utility for images distrosInfo file
copy: src=files/distrosInfo.py dest=/home/ubuntu/distrosInfo.py mode=0755
handlers:
- name: restart nginx
become: True
service: name=nginx state=restarted