-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_lab.yaml
More file actions
89 lines (82 loc) · 2.38 KB
/
create_lab.yaml
File metadata and controls
89 lines (82 loc) · 2.38 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
---
- name: Create VMs and configure them
hosts: localhost
become: false
gather_facts: false
collections:
- community.vmware
pre_tasks:
- name: Load variables
include_vars: variables.yaml
tasks:
- name: Create VMs
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: "{{ vcenter_validate_certs | bool }}"
datacenter: "{{ vcenter_datacenter }}"
cluster: "{{ vcenter_cluster }}"
folder: "{{ vcenter_vm_folder }}"
name: "{{ item }}"
guest_id: "rhel9_64Guest"
state: poweredon
hardware:
memory_mb: 2048
num_cpus: 1
scsi: paravirtual
disk:
- size_gb: 16
type: thin
datastore: "{{ vcenter_datastore }}"
networks:
- name: "{{ vcenter_network }}"
device_type: vmxnet3
connected: true
wait_for_ip_address: true
loop:
- frontend
- middleware
- backend
register: vm_info
delegate_to: localhost
- name: Wait for SSH to be available
ansible.builtin.wait_for:
host: "{{ item.instance.ipv4 }}"
port: 22
delay: 30
timeout: 300
state: started
loop: "{{ vm_info.results }}"
- name: Add user 'app' with sudo privileges
ansible.builtin.user:
name: app
password: "{{ 'mypassword' | password_hash('sha512') }}"
shell: /bin/bash
groups: sudo
append: yes
become: true
delegate_to: "{{ item.instance.ipv4 }}"
loop: "{{ vm_info.results }}"
- name: Allow 'app' user to use sudo without password
ansible.builtin.copy:
dest: "/etc/sudoers.d/app"
content: "app ALL=(ALL) NOPASSWD: ALL"
mode: "0440"
become: true
delegate_to: "{{ item.instance.ipv4 }}"
loop: "{{ vm_info.results }}"
- name: Install VMware Tools
ansible.builtin.yum:
name: open-vm-tools
state: present
become: true
delegate_to: "{{ item.instance.ipv4 }}"
loop: "{{ vm_info.results }}"
- name: Update all packages
ansible.builtin.yum:
name: "*"
state: latest
become: true
delegate_to: "{{ item.instance.ipv4 }}"
loop: "{{ vm_info.results }}"