-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Debian Bookworm switches DNS management from resolvconf to systemd-resolved. This change results in Bookworm instances having an incompatible hostname resolution configuration. Since we rely on cloud-init to automatically configure some of our DNS settings we need to adjust the configuration of Netplan (used by cloud-init) to get the correct configuration for our system. The issue is that Netplan uses a default of false for the value of dhcp4-overrides.use-domains and cloud-init does not explicitly set this key or provide a means to do so. We remedy this by modifying the cloud-init configuration of Bookworm instances to use a Python script to adjust the Netplan configuration and then re-apply Netplan to enable our desired configuration. Co-authored-by: Shane Frasier <[email protected]>
- Loading branch information
Showing
9 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
- hosts: bastion,docker,nessus,nmap | ||
name: Perform additional tasks to support Debian Bookworm | ||
become: yes | ||
become_method: ansible.builtin.sudo | ||
tasks: | ||
# We have a cloud-init script to fix the Netplan configuration that needs | ||
# this Python package. | ||
- name: Ensure the PyYAML package is installed | ||
ansible.builtin.package: | ||
name: | ||
- python3-yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python3 | ||
|
||
"""Append the necessary DHCP options to the Netplan configuration. | ||
The Netplan configuration is created by cloud-init, but it needs to be | ||
slightly modified and reapplied. This script takes care of the | ||
modification. | ||
See these issues for more details: | ||
- cisagov/skeleton-packer#300 | ||
- canonical/cloud-init#4764 | ||
This file is a template. It should be processed by Terraform. | ||
""" | ||
|
||
# Third-Party Libraries | ||
import yaml | ||
|
||
# Inputs from Terraform | ||
NETPLAN_CONFIG = "${netplan_config}" | ||
|
||
with open(NETPLAN_CONFIG) as f: | ||
# Load the current Netplan configuration | ||
config = yaml.safe_load(f) | ||
# Add a dhcp4-overrides section to each network | ||
config["network"]["ethernets"] = { | ||
k: v | {"dhcp4-overrides": {"use-domains": True}} | ||
for (k, v) in config["network"]["ethernets"].items() | ||
} | ||
|
||
# Write the results back out to the Netplan configuration file | ||
with open(NETPLAN_CONFIG, "w") as f: | ||
f.write(yaml.dump(config)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
|
||
# There is a Python script that fixes the DHCP4 options in the Netplan | ||
# configuration already generated by cloud-init. The following simply | ||
# reapplies the Netplan configuration after the modification. | ||
runcmd: | ||
- [netplan, apply] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters