diff --git a/ansible/roles/base/tasks/redhat.yml b/ansible/roles/base/tasks/redhat.yml index 852134df..0985cd1d 100644 --- a/ansible/roles/base/tasks/redhat.yml +++ b/ansible/roles/base/tasks/redhat.yml @@ -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 diff --git a/ansible/roles/configure/tasks/redhat.yml b/ansible/roles/configure/tasks/redhat.yml index d9c7825f..c8b1490f 100644 --- a/ansible/roles/configure/tasks/redhat.yml +++ b/ansible/roles/configure/tasks/redhat.yml @@ -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. diff --git a/builds/linux/rhel/8/data/ks.pkrtpl.hcl b/builds/linux/rhel/8/data/ks.pkrtpl.hcl index 354c141b..4361e8a3 100644 --- a/builds/linux/rhel/8/data/ks.pkrtpl.hcl +++ b/builds/linux/rhel/8/data/ks.pkrtpl.hcl @@ -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 diff --git a/builds/linux/rhel/8/linux-rhel.pkr.hcl b/builds/linux/rhel/8/linux-rhel.pkr.hcl index 1d8c1774..81a3de09 100644 --- a/builds/linux/rhel/8/linux-rhel.pkr.hcl +++ b/builds/linux/rhel/8/linux-rhel.pkr.hcl @@ -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 @@ -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}}", ] } diff --git a/builds/linux/rhel/8/variables.pkr.hcl b/builds/linux/rhel/8/variables.pkr.hcl index d5edca0e..75496912 100644 --- a/builds/linux/rhel/8/variables.pkr.hcl +++ b/builds/linux/rhel/8/variables.pkr.hcl @@ -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." diff --git a/builds/linux/rhel/9/data/ks.pkrtpl.hcl b/builds/linux/rhel/9/data/ks.pkrtpl.hcl index fd5de8dd..887e74df 100644 --- a/builds/linux/rhel/9/data/ks.pkrtpl.hcl +++ b/builds/linux/rhel/9/data/ks.pkrtpl.hcl @@ -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 != "" ~} diff --git a/builds/linux/rhel/9/linux-rhel.pkr.hcl b/builds/linux/rhel/9/linux-rhel.pkr.hcl index 7069a729..697003aa 100644 --- a/builds/linux/rhel/9/linux-rhel.pkr.hcl +++ b/builds/linux/rhel/9/linux-rhel.pkr.hcl @@ -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 @@ -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}}", ] } diff --git a/builds/linux/rhel/9/variables.pkr.hcl b/builds/linux/rhel/9/variables.pkr.hcl index 3c4c573e..e670846a 100644 --- a/builds/linux/rhel/9/variables.pkr.hcl +++ b/builds/linux/rhel/9/variables.pkr.hcl @@ -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." diff --git a/builds/rhsm.pkrvars.hcl.example b/builds/rhsm.pkrvars.hcl.example index 5af88ee5..112126d3 100644 --- a/builds/rhsm.pkrvars.hcl.example +++ b/builds/rhsm.pkrvars.hcl.example @@ -8,5 +8,6 @@ */ // Red Hat Subscription Manager Credentials +rhsm_enabled = true rhsm_username = "packer" rhsm_password = "VMw@re123!" diff --git a/docs/getting-started/configure.md b/docs/getting-started/configure.md index ebb71f1b..98c951ad 100644 --- a/docs/getting-started/configure.md +++ b/docs/getting-started/configure.md @@ -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" ```