Skip to content

Commit

Permalink
feat: add rhsm_enabled to enable or disable Red Hat subscription manager
Browse files Browse the repository at this point in the history
Added rhsm_enabled variable to enable or disable Red Hat Subscription
Manager

Signed-off-by: Fabien SEISEN <seisen@gmail.com>
  • Loading branch information
nesies committed Nov 6, 2024
1 parent fb37d5e commit 8d7633d
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 2 deletions.
4 changes: 3 additions & 1 deletion ansible/roles/base/tasks/redhat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
msg: "OS: {{ ansible_distribution }} {{ ansible_distribution_version }}"

- name: Checking the Red Hat Subscription Manager status.
when: ansible_distribution == 'RedHat'
when:
- ansible_distribution == 'RedHat'
- rhsm_enabled
ansible.builtin.command:
cmd: subscription-manager status
register: result
Expand Down
4 changes: 3 additions & 1 deletion ansible/roles/configure/tasks/redhat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
- name: Disconnecting from Red Hat Subscription Manager.
community.general.redhat_subscription:
state: absent
when: ansible_distribution == 'RedHat'
when:
- ansible_distribution == 'RedHat'
- rhsm_enabled

# Tasks for configuring SSH for public key authentication.
- name: Configuring SSH for Public Key Authentication without cloud-init.
Expand Down
4 changes: 4 additions & 0 deletions builds/linux/rhel/8/data/ks.pkrtpl.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ skipx

### Post-installation commands.
%post
%{ if rhsm_enabled ~}
/usr/sbin/subscription-manager register --username ${rhsm_username} --password ${rhsm_password} --autosubscribe --force
/usr/sbin/subscription-manager repos --enable "codeready-builder-for-rhel-8-x86_64-rpms"
%{ else ~}
dnf remove --assumeyes subscription-manager
%{ endif ~}
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf makecache
dnf install -y sudo open-vm-tools perl
Expand Down
2 changes: 2 additions & 0 deletions builds/linux/rhel/8/linux-rhel.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ locals {
build_username = var.build_username
build_password = var.build_password
build_password_encrypted = var.build_password_encrypted
rhsm_enabled = var.rhsm_enabled
rhsm_username = var.rhsm_username
rhsm_password = var.rhsm_password
vm_guest_os_language = var.vm_guest_os_language
Expand Down Expand Up @@ -231,6 +232,7 @@ build {
"--extra-vars", "ansible_username=${var.ansible_username}",
"--extra-vars", "ansible_key='${var.ansible_key}'",
"--extra-vars", "enable_cloudinit=${var.vm_guest_os_cloudinit}",
"--extra-vars", "{\"rhsm_enabled\": ${var.rhsm_enabled}}",
]
}

Expand Down
6 changes: 6 additions & 0 deletions builds/linux/rhel/8/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

// Red Hat Subscription Manager Credentials

variable "rhsm_enabled" {
type = bool
description = "Enable Red Hat Subscription Manager."
sensitive = false
}

variable "rhsm_username" {
type = string
description = "The username to Red Hat Subscription Manager."
Expand Down
5 changes: 5 additions & 0 deletions builds/linux/rhel/9/data/ks.pkrtpl.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,14 @@ skipx

### Post-installation commands.
%post
%{ if rhsm_enabled ~}
/usr/sbin/subscription-manager register --username ${rhsm_username} --password ${rhsm_password} --autosubscribe --force
/usr/sbin/subscription-manager repos --enable "codeready-builder-for-rhel-9-x86_64-rpms"
%{ else ~}
dnf remove --assumeyes subscription-manager
%{ endif ~}
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm

dnf makecache
dnf install -y sudo open-vm-tools perl
%{ if additional_packages != "" ~}
Expand Down
2 changes: 2 additions & 0 deletions builds/linux/rhel/9/linux-rhel.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ locals {
build_username = var.build_username
build_password = var.build_password
build_password_encrypted = var.build_password_encrypted
rhsm_enabled = var.rhsm_enabled
rhsm_username = var.rhsm_username
rhsm_password = var.rhsm_password
vm_guest_os_language = var.vm_guest_os_language
Expand Down Expand Up @@ -231,6 +232,7 @@ build {
"--extra-vars", "ansible_username=${var.ansible_username}",
"--extra-vars", "ansible_key='${var.ansible_key}'",
"--extra-vars", "enable_cloudinit=${var.vm_guest_os_cloudinit}",
"--extra-vars", "{\"rhsm_enabled\": ${var.rhsm_enabled}}",
]
}

Expand Down
16 changes: 16 additions & 0 deletions builds/linux/rhel/9/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,24 @@
// BLOCK: variable
// Defines the input variables.

// Additional yum repositories
variable "yum_repositories" {
type = list(object({
name = string
url = string
}))
description = "Additional yum repositories"
sensitive = false
}

// Red Hat Subscription Manager Credentials

variable "rhsm_enabled" {
type = bool
description = "Enable Red Hat Subscription Manager."
sensitive = false
}

variable "rhsm_username" {
type = string
description = "The username to Red Hat Subscription Manager."
Expand Down
1 change: 1 addition & 0 deletions builds/rhsm.pkrvars.hcl.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
*/

// Red Hat Subscription Manager Credentials
rhsm_enabled = true
rhsm_username = "packer"
rhsm_password = "VMw@re123!"
2 changes: 2 additions & 0 deletions docs/getting-started/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ additional_packages = ["git", "make", "vim"]
Edit the `config/redhat.pkrvars.hcl` file to configure the credentials for your Red Hat Subscription
Manager account.
You can also disable Red Hat Subscription Manger by setting `rhsm_enabled = false`.
```hcl linenums="1" title="config/rhsm.pkrvars.hcl" hl_lines="1"
--8<-- "./builds/rhsm.pkrvars.hcl.example:10:100"
```
Expand Down

0 comments on commit 8d7633d

Please sign in to comment.