Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Ensures system_info is written in all cases #69

Closed
wants to merge 1 commit into from

Conversation

lorengordon
Copy link
Member

@lorengordon lorengordon commented Nov 22, 2022

In the latest OL8 updates, the cloud.cfg in the chroot gets a system_info section that looks like this:

system_info:
  # This will affect which distro class gets used
  # Unknown/fallback distro.
  distro: ubuntu 

That resulted in failures when the amigen8 logic attempted to figure out the cloud-init user, because there was no user at all:

	2022-11-22T17:08:29.954Z	amazon-ebs.minimal-ol-8-hvm: + ConfigureCloudInit
	2022-11-22T17:08:31.980Z	amazon-ebs.minimal-ol-8-hvm: + local CLOUDCFG
	2022-11-22T17:08:31.980Z	amazon-ebs.minimal-ol-8-hvm: + local CLINITUSR
	2022-11-22T17:08:31.980Z	amazon-ebs.minimal-ol-8-hvm: + CLOUDCFG=/mnt/ec2-root/etc/cloud/cloud.cfg
	2022-11-22T17:08:31.980Z
    amazon-ebs.minimal-ol-8-hvm: ++ grep -E 'name: (maintuser|centos|ec2-user|cloud-user)' /mnt/ec2-root/etc/cloud/cloud.cfg
	2022-11-22T17:08:31.980Z	amazon-ebs.minimal-ol-8-hvm: ++ awk '{print $2}'
	2022-11-22T17:08:31.980Z	amazon-ebs.minimal-ol-8-hvm: + CLINITUSR=
	2022-11-22T17:08:31.980Z	amazon-ebs.minimal-ol-8-hvm: + err_exit 'Failure encountered with PostBuild.sh' 

This patch updates the logic to replace any system_info stanza with the standard one used throughout amigen projects. The primary change in logic to enable that is from this:

sed -i '/^system_info/,/^ ssh_svcname/d' "${CLOUDCFG}"

to this:

sed -i '/^system_info/,/^$/d' "${CLOUDCFG}"

@lorengordon lorengordon requested a review from a team November 22, 2022 22:16

# Delete current "system_info:" block
err_exit "Nuking standard system_info block..." NONE
sed -i '/^system_info/,/^$/d' "${CLOUDCFG}" || \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this now is a "from to end" rather than a "from <TOKEN_1> to <TOKEN_2>" range, does this continue to work across all EL8s? Which is to ask, has /^system_info/ been moved to be the last configuration-block in not ust the OL8 version but all EL8 versions of the file?

I'm going to go look and answer my own question, but figured I'd ask here while I wait for instances to spin up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Ok. Looking at the one in the official RHEL 8 (you mentioned an "official" Oracle 8, but I'm not finding any such beast), looks like the file ends:

system_info:
  default_user:
    name: cloud-user
    lock_passwd: true
    gecos: Cloud User
    groups: [adm, systemd-journal]
    sudo: ["ALL=(ALL) NOPASSWD:ALL"]
    shell: /bin/bash
  distro: rhel
  paths:
    cloud_dir: /var/lib/cloud
    templates_dir: /etc/cloud/templates
  ssh_svcname: sshd

# vim:syntax=yaml

My vague recollection is that I'd originally chosen the range-token method because I wanted to preserve the content after the system_info: stanza, even though it's, effectively, null.

Copy link
Member

@ferricoxide ferricoxide Nov 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rocky ends similarly to RHEL (with the commented out vim:syntax=yaml line:

$ sed -n '/^system_info/,$p' /etc/cloud/cloud.cfg
system_info:
  default_user:
    name: rocky
    lock_passwd: true
    gecos: Cloud User
    groups: [adm, systemd-journal]
    sudo: ["ALL=(ALL) NOPASSWD:ALL"]
    shell: /bin/bash
  distro: rhel
  paths:
    cloud_dir: /var/lib/cloud
    templates_dir: /etc/cloud/templates
  ssh_svcname: sshd

# vim:syntax=yaml

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so CentOS 8 Stream doesn't have that token:

$ sed -n '/^system_info/,$p' /etc/cloud/cloud.cfg
system_info:
   # This will affect which distro class gets used
   distro: centos
   # Default user name + that default users groups (if added/used)
   default_user:
     name: centos
     lock_passwd: True
     gecos: centos Cloud User
     groups: [wheel, adm, systemd-journal]
     sudo: ["ALL=(ALL) NOPASSWD:ALL"]
     shell: /bin/bash
   # Other config here will be given to the distro class and/or path classes
   paths:
      cloud_dir: /var/lib/cloud/
      templates_dir: /etc/cloud/templates/
   ssh_svcname: sshd

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nor does Alma:

$ sed -n '/^system_info/,$p' /etc/cloud/cloud.cfg
system_info:
   # This will affect which distro class gets used
   distro: almalinux
   # Default user name + that default users groups (if added/used)
   default_user:
     name: ec2-user
     lock_passwd: True
     gecos: almalinux Cloud User
     groups: [adm, systemd-journal]
     sudo: ["ALL=(ALL) NOPASSWD:ALL"]
     shell: /bin/bash
   # Other config here will be given to the distro class and/or path classes
   paths:
      cloud_dir: /var/lib/cloud/
      templates_dir: /etc/cloud/templates/
   ssh_svcname: sshd

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposed method won't adversely effect things – since the content after the system_info block is, effectively, "decorative". I just hate obliterating stuff.

That said, the basis for the proposed change is in reference to an "official" Oracle Linux 8 AMI that I am failing to find as published by either AWS (as RHEL and CentOS are) or Oracle itself. All I'm seeing is third party OL8 AMIs. Can you point me at the "official" OL8 AMI (whose cloud.cfg created the need for this PR)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the cloud.cfg in the base AMI:

system_info:
  default_user:
    name: ec2-user
    lock_passwd: true
    gecos: Cloud User
    groups: [wheel, adm, systemd-journal]
    sudo: ["ALL=(ALL) NOPASSWD:ALL"]
    shell: /bin/bash
  distro: rhel
  paths:
    cloud_dir: /var/lib/cloud
    templates_dir: /etc/cloud/templates
  ssh_svcname: sshd

Meaing the previous sed statement ought to have worked. Updating the instance, now, to see if the cloud.cfg content has changed…

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the problem can be reproduced outside of using chroot or similar to create a fresh new image.

@lorengordon lorengordon changed the title Ensures system_info is written in all cases WIP: Ensures system_info is written in all cases Nov 23, 2022
@lorengordon lorengordon marked this pull request as draft November 23, 2022 17:06
@lorengordon
Copy link
Member Author

Ok, converted to draft, pending a reply from Oracle on their broken packaging. We'll release the Nov AMIs without OL8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants