-
Notifications
You must be signed in to change notification settings - Fork 4
/
simple_vm_deploy.yml
102 lines (97 loc) · 4.49 KB
/
simple_vm_deploy.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
- name: Simple vm deploy #edit vmname variable - use -l filter to specify cluster vs. full inventory
hosts: edge
vars:
- vmname: ubuntu
connection: local
gather_facts: false
strategy: host_pinned # free #allows each cluster to start next task before all clusters have finished current task
environment: #if set here - hypercore modules will automatically use this for each remote cluster - avoiding need to specify cluster_instance for each test
SC_HOST: "https://{{ inventory_hostname }}"
SC_USERNAME: "{{ scale_user | default('admin') }}"
SC_PASSWORD: "{{ scale_pass | default('admin') }}"
SC_TIMEOUT: 60
tasks:
- name: Ubuntu20_04 template - Ubuntu 20.04 - import if not present # used to clone and cloud-init target VM
scale_computing.hypercore.vm_import:
cluster_instance:
host: "https://{{inventory_hostname }}"
username: "{{scale_user}}"
password: "{{scale_pass}}"
vm_name: ubuntu20_04
http_uri:
path: 'https://github.com/ddemlow/RestAPIExamples/raw/master/ubuntu20_04-cloud-init'
file_name: ubuntu20_04-cloud-init.xml
# until: ubuntu20_04.msg is search("import complete") #doesnt' check if vm already exists
retries: 5
delay: 1
ignore_errors: false # import errors are not uncommon depdending on network connection to smb / https source
register: ubuntu20_04
- name: Clone and configure ad hoc "{{ vmname }}"
scale_computing.hypercore.vm_clone:
cluster_instance:
host: "https://{{inventory_hostname }}"
username: "{{scale_user}}"
password: "{{scale_pass}}"
vm_name: "{{vmname}}"
source_vm_name: ubuntu20_04
cloud_init:
user_data: |
#cloud-config
password: "password"
chpasswd: { expire: False }
ssh_pwauth: True
ssh_authorized_keys: # Add your ssh public key for publickey authentication
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDihWWhjoPj8KVLtdLDwNJQ71zi9An0iUFjefRWu2Eju [email protected]
disable_root: false # allow ssh root login
ssh_import_id: gh:ddemlow
apt: {sources: {docker.list: {source: 'deb [arch=amd64] https://download.docker.com/linux/ubuntu $RELEASE stable', keyid: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88}}}
package_update: true
package_upgrade: true
packages: [qemu-guest-agent, docker-ce, docker-ce-cli, docker-compose, ansible, git, unzip]
bootcmd:
- [ sh, -c, 'sudo echo GRUB_CMDLINE_LINUX="nomodeset" >> /etc/default/grub' ]
- [ sh, -c, 'sudo echo GRUB_GFXPAYLOAD_LINUX="1024x768" >> /etc/default/grub' ]
- [ sh, -c, 'sudo echo GRUB_DISABLE_LINUX_UUID=true >> /etc/default/grub' ]
- [ sh, -c, 'sudo update-grub' ]
runcmd:
- [ systemctl, restart, --no-block, qemu-guest-agent ]
write_files:
# configure docker daemon to be accessible remotely via TCP on socket 2375
- content: |
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H unix:// -H tcp://0.0.0.0:2375
path: /etc/systemd/system/docker.service.d/options.conf
- content: "{{ inventory_hostname }}"
path: /clusterip.txt
meta_data: |
dsmode: local
local-hostname: "{{ vmname }}"
- name: Disk desired configuration for "{{ vmname }}"
scale_computing.hypercore.vm_disk:
cluster_instance:
host: "https://{{inventory_hostname }}"
username: "{{scale_user}}"
password: "{{scale_pass}}"
vm_name: "{{ vmname }}"
items:
- disk_slot: 0
type: virtio_disk
size: "{{ '400 GB' | human_to_bytes }}" # 50GB | human to bytes results in 53.7GB VSD in Hypercore
state: present
- name: Vm desired configuration and state for "{{ vmname }}"
scale_computing.hypercore.vm_params:
cluster_instance:
host: "https://{{inventory_hostname }}"
username: "{{scale_user}}"
password: "{{scale_pass}}"
vm_name: "{{vmname}}"
memory: "{{ '4 GB' | human_to_bytes }}"
description:
tags:
- ansible
- "{{ site_name }}"
- ansible_group__"{{vmname}}" # this will create tag used by hypercore inventory plugin when executing towards VM hosts
vcpu: 4
power_state: start