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

Set hostname for EC2 and OpenStack from metadata #21

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions dracut/30ignition/flatcar-metadata-hostname.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Flatcar Metadata Hostname Agent
DefaultDependencies=false
Before=initrd.target
After=systemd-networkd.service initrd-root-fs.target
Wants=systemd-networkd.service initrd-root-fs.target

# Ensure Ignition can overwrite /etc/hostname
Before=ignition-files.service

[Service]
Type=oneshot
ExecStart=/usr/bin/coreos-metadata --cmdline --hostname=/sysroot/etc/hostname
14 changes: 14 additions & 0 deletions dracut/30ignition/flatcar-openstack-hostname.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Flatcar OpenStack Metadata Hostname Agent
DefaultDependencies=false
Before=initrd.target
After=systemd-networkd.service initrd-root-fs.target
Wants=systemd-networkd.service initrd-root-fs.target

# Ensure Ignition can overwrite /etc/hostname
Before=ignition-files.service

[Service]
Type=oneshot
# Special case: the oem_id openstack does not match the afterburn name openstack-metadata
ExecStart=/usr/bin/coreos-metadata --provider openstack-metadata --hostname=/sysroot/etc/hostname
6 changes: 6 additions & 0 deletions dracut/30ignition/ignition-generator
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ Conflicts=emergency.service
Conflicts=dracut-emergency.service
EOF
fi
if [[ $(cmdline_arg flatcar.oem.id) == "ec2" ]] || [[ $(cmdline_arg coreos.oem.id) == "ec2" ]]; then
add_requires flatcar-metadata-hostname.service
fi
if [[ $(cmdline_arg flatcar.oem.id) == "openstack" ]] || [[ $(cmdline_arg coreos.oem.id) == "openstack" ]]; then
add_requires flatcar-openstack-hostname.service
fi
fi

# Write ignition-setup.service customized for PXE/ISO or regular boot
Expand Down
6 changes: 6 additions & 0 deletions dracut/30ignition/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ install() {
inst_simple "$moddir/flatcar-static-network.service" \
"$systemdsystemunitdir/flatcar-static-network.service"

inst_simple "$moddir/flatcar-metadata-hostname.service" \
"$systemdsystemunitdir/flatcar-metadata-hostname.service"

inst_simple "$moddir/flatcar-openstack-hostname.service" \
"$systemdsystemunitdir/flatcar-openstack-hostname.service"

inst_rules \
60-cdrom_id.rules \
66-azure-storage.rules \
Expand Down