Skip to content

Commit 5c07b06

Browse files
burnsjared0415tenthirtyam
authored andcommitted
feat: option to enable cloud-init on rhel 9 and 8
- Added the cloud-init option for RHEL 9. - Added the cloud-init option for RHEL 8. Signed-off-by: Jared Burns <jared.burns@broadcom.com>
1 parent d568ef2 commit 5c07b06

File tree

10 files changed

+73
-8
lines changed

10 files changed

+73
-8
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
the guest operating systems.
1111
[#874](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/874),
1212
[#877](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/877)
13-
- Adds option to enable cloud-init on Debian 12.5.
13+
- Adds option to enable cloud-init on Debian 12.
1414
[#883](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/883)
15+
- Adds option to enabled cloud-init on Red Hat Enterprise Linux 9.
16+
[#888](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/888)
17+
- Adds option to enabled cloud-init on Red Hat Enterprise Linux 8.
18+
- [#888](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/888))
1519

1620
## v0.19.1
1721

ansible/roles/base/tasks/linux.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@
5959
name: "*"
6060
state: latest # noqa package-latest
6161
update_cache: true
62-
62+
- name: "Installing Cloud-init."
63+
dnf:
64+
name: cloud-init
65+
state: latest
66+
when: enable_cloudinit == 'true'
6367
- name: "Installing additional packages."
6468
dnf:
6569
name: "{{ additional_packages[ansible_os_family] }}"

ansible/roles/configure/tasks/redhat.yml

+39-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
redhat_subscription:
55
state: absent
66
when: ansible_distribution == 'RedHat'
7-
7+
88
# Tasks for configuring SSH for public key authentication.
99
- name: "Configuring SSH for Public Key Authentication."
1010
block:
@@ -16,6 +16,29 @@
1616
path: /etc/ssh/sshd_config
1717
regexp: '^PubkeyAuthentication'
1818
line: 'PubkeyAuthentication yes'
19+
when: enable_cloudinit == 'false'
20+
block:
21+
- lineinfile:
22+
path: /etc/ssh/sshd_config
23+
regexp: '^PermitRootLogin'
24+
line: 'PermitRootLogin no'
25+
- lineinfile:
26+
path: /etc/ssh/sshd_config
27+
regexp: '^PubkeyAuthentication'
28+
line: 'PubkeyAuthentication yes'
29+
- lineinfile:
30+
path: /etc/ssh/sshd_config
31+
regexp: '^PasswordAuthentication'
32+
line: 'PasswordAuthentication yes'
33+
when: enable_cloudinit == 'true'
34+
35+
# Tasks for disabling cloud-init ssh module.
36+
- name: "Disable cloud-init ssh module"
37+
lineinfile:
38+
path: /etc/cloud/cloud.cfg
39+
regexp: '^ssh_pwauth: false'
40+
line: 'ssh_pwauth: true'
41+
when: enable_cloudinit == 'true'
1942

2043
# Tasks for setting the hostname.
2144
- name: "Setting the hostname."
@@ -34,3 +57,18 @@
3457
name: sshd
3558
state: restarted
3659
daemon_reload: true
60+
61+
# Tasks for configuring cloud-init.
62+
- name: "Configuring cloud-init."
63+
block:
64+
- name: "Message: Configuring cloud-init"
65+
debug:
66+
msg: "Configuring cloud-init"
67+
- blockinfile:
68+
path: /etc/cloud/cloud.cfg
69+
block: |
70+
disable_vmware_customization: false
71+
- copy:
72+
content: "datasource_list: [ VMware, OVF, None ]"
73+
dest: /etc/cloud/cloud.cfg.d/90_dpkg.cfg
74+
when: enable_cloudinit == 'true'

builds/linux/rhel/8/linux-rhel.pkr.hcl

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ locals {
5959
vm_guest_os_language = var.vm_guest_os_language
6060
vm_guest_os_keyboard = var.vm_guest_os_keyboard
6161
vm_guest_os_timezone = var.vm_guest_os_timezone
62+
vm_guest_os_cloudinit = var.vm_guest_os_cloudinit
6263
network = templatefile("${abspath(path.root)}/data/network.pkrtpl.hcl", {
6364
device = var.vm_network_device
6465
ip = var.vm_ip_address
@@ -176,6 +177,7 @@ source "vsphere-iso" "linux-rhel" {
176177
ovf = var.common_content_library_ovf
177178
destroy = var.common_content_library_destroy
178179
skip_import = var.common_content_library_skip_export
180+
179181
}
180182
}
181183

@@ -214,6 +216,7 @@ build {
214216
"--extra-vars", "build_key='${var.build_key}'",
215217
"--extra-vars", "ansible_username=${var.ansible_username}",
216218
"--extra-vars", "ansible_key='${var.ansible_key}'",
219+
"--extra-vars", "enable_cloudinit=${var.vm_guest_os_cloudinit}",
217220
]
218221
}
219222

builds/linux/rhel/8/linux-rhel.pkrvars.hcl.example

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ vm_guest_os_version = "8.9"
1717

1818
// Virtual Machine Guest Operating System Setting
1919
vm_guest_os_type = "rhel8_64Guest"
20+
vm_guest_os_cloudinit = false
2021

2122
// Virtual Machine Hardware Settings
2223
vm_firmware = "efi-secure"
@@ -34,8 +35,8 @@ vm_network_card = "vmxnet3"
3435

3536
// Removable Media Settings
3637
iso_datastore_path = "iso/linux/rhel"
37-
iso_content_library_item = "rhel-9.3-x86_64-dvd"
38-
iso_file = "rhel-9.3-x86_64-dvd.iso"
38+
iso_content_library_item = "rhel-8.9-x86_64-dvd"
39+
iso_file = "rhel-8.9-x86_64-dvd.iso"
3940

4041
// Boot Settings
4142
vm_boot_order = "disk,cdrom"

builds/linux/rhel/8/variables.pkr.hcl

+6
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ variable "vm_guest_os_type" {
136136
description = "The guest operating system type, also know as guestid."
137137
}
138138

139+
variable "vm_guest_os_cloudinit" {
140+
type = bool
141+
description = "Enable cloud-init for the guest operating system."
142+
default = false
143+
}
144+
139145
variable "vm_firmware" {
140146
type = string
141147
description = "The virtual machine firmware."

builds/linux/rhel/9/linux-rhel.pkr.hcl

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ locals {
5959
vm_guest_os_language = var.vm_guest_os_language
6060
vm_guest_os_keyboard = var.vm_guest_os_keyboard
6161
vm_guest_os_timezone = var.vm_guest_os_timezone
62+
vm_guest_os_cloudinit = var.vm_guest_os_cloudinit
6263
network = templatefile("${abspath(path.root)}/data/network.pkrtpl.hcl", {
6364
device = var.vm_network_device
6465
ip = var.vm_ip_address
@@ -215,6 +216,7 @@ build {
215216
"--extra-vars", "build_key='${var.build_key}'",
216217
"--extra-vars", "ansible_username=${var.ansible_username}",
217218
"--extra-vars", "ansible_key='${var.ansible_key}'",
219+
"--extra-vars", "enable_cloudinit=${var.vm_guest_os_cloudinit}",
218220
]
219221
}
220222

builds/linux/rhel/9/linux-rhel.pkrvars.hcl.example

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ vm_guest_os_version = "9.3"
1717

1818
// Virtual Machine Guest Operating System Setting
1919
vm_guest_os_type = "rhel9_64Guest"
20+
vm_guest_os_cloudinit = false
2021

2122
// Virtual Machine Hardware Settings
2223
vm_firmware = "efi-secure"

builds/linux/rhel/9/variables.pkr.hcl

+6
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ variable "vm_guest_os_type" {
136136
description = "The guest operating system type, also know as guestid."
137137
}
138138

139+
variable "vm_guest_os_cloudinit" {
140+
type = bool
141+
description = "Enable cloud-init for the guest operating system."
142+
default = false
143+
}
144+
139145
variable "vm_firmware" {
140146
type = string
141147
description = "The virtual machine firmware."

docs/index.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ This project supports the following guest operating systems:
1919
| :--- | :--- | :--- | :--- | :--- | :--- |
2020
| :simple-vmware: &nbsp;&nbsp; VMware Photon OS @span | 5.0 | :octicons-check-circle-24:{ .green } | :octicons-x-circle-24: | :octicons-check-circle-24:{ .green } | :octicons-x-circle-24: |
2121
| | 4.0 | :octicons-check-circle-24:{ .green } | :octicons-x-circle-24: | :octicons-check-circle-24:{ .green } | :octicons-x-circle-24: |
22-
| :fontawesome-brands-debian: &nbsp;&nbsp; Debian @span | 12 | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } |
22+
| :fontawesome-brands-debian: &nbsp;&nbsp; Debian @span | 12 | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } |
2323
| | 11 | :octicons-check-circle-24:{ .green } | :octicons-x-circle-24: | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } |
2424
| :fontawesome-brands-ubuntu: &nbsp;&nbsp; Ubuntu Server @span | 23.10 | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } |
2525
| | 22.04 LTS | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } |
2626
| | 20.04 LTS | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } |
27-
| :fontawesome-brands-redhat: &nbsp;&nbsp; Red Hat Enterprise Linux @span | 9 | :octicons-check-circle-24:{ .green } | :octicons-x-circle-24: | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } |
28-
| | 8 | :octicons-check-circle-24:{ .green } | :octicons-x-circle-24: | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } |
27+
| :fontawesome-brands-redhat: &nbsp;&nbsp; Red Hat Enterprise Linux @span | 9 | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } |
28+
| | 8 | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } |
2929
| | 7 | :octicons-check-circle-24:{ .green } | :octicons-x-circle-24: | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } |
3030
| :fontawesome-brands-linux: &nbsp;&nbsp; AlmaLinux OS @span | 9 | :octicons-check-circle-24:{ .green } | :octicons-x-circle-24: | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } |
3131
| | 8 | :octicons-check-circle-24:{ .green } | :octicons-x-circle-24: | :octicons-check-circle-24:{ .green } | :octicons-check-circle-24:{ .green } |

0 commit comments

Comments
 (0)