-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvm_centos.amd64.yaml
More file actions
249 lines (236 loc) · 9.15 KB
/
vm_centos.amd64.yaml
File metadata and controls
249 lines (236 loc) · 9.15 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
tosca_definitions_version: cloudify_dsl_1_3
imports:
- http://www.getcloudify.org/spec/cloudify/4.6/types.yaml
- https://raw.githubusercontent.com/cloudify-incubator/cloudify-utilities-plugin/1.15.3/plugin.yaml
- https://raw.githubusercontent.com/cloudify-incubator/cloudify-libvirt-plugin/0.8.1/plugin.yaml
relationships:
vm_connected_to_storage:
derived_from: cloudify.relationships.contained_in
target_interfaces:
cloudify.interfaces.relationship_lifecycle:
preconfigure:
implementation: scripts/vm_preconfigure.py
executor: central_deployment_agent
inputs: {}
node_templates:
common_network:
type: cloudify.libvirt.network
interfaces:
cloudify.interfaces.lifecycle:
create:
inputs:
params:
dev: virbr1
forwards:
- mode: nat
ips:
- address: 192.168.142.1
netmask: 255.255.255.0
dhcp:
start: 192.168.142.2
end: 192.168.142.254
vm_download:
type: cloudify.nodes.ApplicationServer
interfaces:
cloudify.interfaces.lifecycle:
create:
implementation: scripts/download_vm.sh
executor: central_deployment_agent
inputs:
CATALOG_URL: https://cloud.centos.org/centos/7/images/
DISK: CentOS-7-x86_64-GenericCloud-1907.qcow2
agent_key:
type: cloudify.keys.nodes.RSAKey
properties:
use_secret_store: false
interfaces:
cloudify.interfaces.lifecycle:
create:
implementation: keys.cloudify_ssh_key.operations.create
inputs:
store_private_key_material: true
cloud_init:
type: cloudify.nodes.CloudInit.CloudConfig
interfaces:
cloudify.interfaces.lifecycle:
create:
inputs:
resource_config:
users:
- name: centos
primary_group: centos
# mkpasswd --method=SHA-512 --rounds=4096
# hash of passw0rd
passwd: $6$rounds=4096$sEbWYCRnr$kV18TY9O9Bkq0DdSo5Zvp8saK0gnpZ3RD.55YvQp1ZuaU89eG/T3UrWRh7s9SzchEjebL9ETr2KyMVHqtiXbQ.
groups: users, admin, wheel
lock_passwd: false
shell: /bin/bash
sudo: ['ALL=(ALL) NOPASSWD:ALL']
ssh_authorized_keys:
- { get_attribute: [agent_key, public_key_export] }
packages:
- [epel-release]
- [deltarpm]
write_files:
- path: /etc/yum.repos.d/custom.repo
content: |
[customrepo]
name=Custom Repository
baseurl=http://localhost:8080/
enabled=0
gpgcheck=0
- path: /etc/nginx/conf.d/repos.conf
content: |
server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name _;
root /usr/share/nginx/html/custom_repository/;
location / {
index index.html index.htm;
autoindex on; #enable listing of directory index
}
}
relationships:
- target: agent_key
type: cloudify.relationships.depends_on
disk_clone:
type: cloudify.nodes.ApplicationServer
interfaces:
cloudify.interfaces.lifecycle:
create:
implementation: scripts/disk_prepere.py
executor: central_deployment_agent
inputs:
disk_image: { get_attribute: [vm_download, vm_image] }
cloud_init: { get_attribute: [cloud_init, cloud_config ] }
configure:
implementation: scripts/copy_disk.py
executor: central_deployment_agent
delete:
implementation: scripts/remove_disk.sh
executor: central_deployment_agent
# backups related section
cloudify.interfaces.snapshot:
create:
implementation: scripts/snapshot_disk_create.py
executor: central_deployment_agent
delete:
implementation: scripts/snapshot_disk_delete.py
executor: central_deployment_agent
relationships:
- target: cloud_init
type: cloudify.relationships.depends_on
- target: vm_download
type: cloudify.relationships.depends_on
qemu_vm:
type: cloudify.libvirt.domain
properties:
agent_config:
install_method: none
interfaces:
cloudify.interfaces.lifecycle:
create:
inputs:
params:
domain_type: qemu
vcpu: 2
# 2 GB
memory_size: 2097152
networks:
- network: { get_attribute: [common_network, resource_id] }
dev: vnet0
relationships:
- target: common_network
type: cloudify.libvirt.relationships.connected_to
- target: disk_clone
type: vm_connected_to_storage
example_node:
type: cloudify.nodes.WebServer
interfaces:
cloudify.interfaces.lifecycle:
create:
implementation: terminal.cloudify_terminal.tasks.run
inputs:
terminal_auth:
smart_device: true
user: centos
key_content: { get_attribute: [agent_key, private_key_export] }
ip: { get_attribute: [qemu_vm, ip] }
warnings:
- Another app is currently holding the yum lock; waiting for it to exit....
calls:
# set terminal properties
- action: echo $LANG
- action: stty rows 200 cols 160
# network fix
- action: sudo ip link set dev eth0 mtu 1400
# space fix
- action: sudo sudo xfs_growfs /
# install packages
- action: sudo yum clean metadata
# need to install epel before any other
- action: sudo yum install -y epel-release deltarpm
# install other rpm's
- action: sudo yum install -y createrepo nginx yum-utils firewalld
# create repository
- action: sudo mkdir -p /usr/share/nginx/html/custom_repository
# download content
- action: sudo curl http://mirror.centos.org/centos/7/os/x86_64/Packages/pciutils-3.5.1-3.el7.x86_64.rpm -o /usr/share/nginx/html/custom_repository/pciutils-3.5.1-3.el7.x86_64.rpm
# enable firewall
- action: sudo systemctl start firewalld > /dev/null || echo "Failed!"
- action: sudo systemctl enable firewalld > /dev/null || echo "Failed!"
# ebnable nginx
- action: sudo systemctl start nginx > /dev/null || echo "Failed!"
- action: sudo systemctl enable nginx > /dev/null || echo "Failed!"
# set rules
- action: sudo firewall-cmd --zone=public --permanent --add-service=http > /dev/null || echo "Failed!"
- action: sudo firewall-cmd --zone=public --permanent --add-port=8080/tcp > /dev/null || echo "Failed!"
- action: sudo firewall-cmd --zone=public --permanent --add-service=ssh > /dev/null || echo "Failed!"
- action: sudo firewall-cmd --reload > /dev/null > /dev/null || echo "Failed!"
# create reposotory
- action: sudo createrepo /usr/share/nginx/html/custom_repository
# fix rights
- action: sudo find /usr/share/nginx/html/custom_repository/ -type f -print | sudo xargs chmod 644 -v > /dev/null || echo "Failed!"
- action: sudo find /usr/share/nginx/html/custom_repository/ -type d -print | sudo xargs chmod 755 -v > /dev/null || echo "Failed!"
cloudify.interfaces.freeze:
fs_prepare:
implementation: terminal.cloudify_terminal.tasks.run
inputs:
terminal_auth:
user: centos
key_content: { get_attribute: [agent_key, private_key_export] }
ip: { get_attribute: [qemu_vm, ip] }
calls:
- action: sudo sync
fs_finalize:
implementation: terminal.cloudify_terminal.tasks.run
inputs:
terminal_auth:
user: centos
key_content: { get_attribute: [agent_key, private_key_export] }
ip: { get_attribute: [qemu_vm, ip] }
calls:
- action: sudo sync
relationships:
- target: qemu_vm
type: cloudify.relationships.contained_in
reuse_vm:
type: cloudify.libvirt.domain
properties:
agent_config:
install_method: none
interfaces:
cloudify.interfaces.lifecycle:
create:
inputs:
use_external_resource: true
resource_id: { get_attribute: [qemu_vm, resource_id] }
start:
implementation: libvirt.cloudify_libvirt.domain_tasks.update
inputs:
params:
memory_size: 1048576
relationships:
- target: example_node
type: cloudify.relationships.depends_on