Skip to content

Commit

Permalink
fix: powervs proxy nodnsupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-freeman committed Nov 11, 2024
1 parent 4f023fd commit 4bb1357
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ fi
EOF
}

provisioner "file" {
destination = "/tmp/nodnsupdate"
content = <<EOF
#!/bin/sh
make_resolv_conf() {
:
}
EOF
}

connection {
# The Bastion host ssh connection is established first, and then the host connection will be made from there.
# Checking Host Key is false when not using bastion_host_key
Expand All @@ -98,13 +108,20 @@ resource "null_resource" "dns_resolv_update" {

depends_on = [null_resource.dns_resolv_files]

# /etc/resolv.conf error 'generated by /usr/sbin/dhclient-script' on some OS Images, avoid overwritten file by 60s sleep
# then configure RHEL nmcli and using script '/etc/dhcp/dhclient-enter-hooks.d/nodnsupdate'
provisioner "local-exec" {
command = "echo '----Sleep 60s to ensure Virtual Server is ready-----' && sleep 60"
}

provisioner "remote-exec" {
inline = [
"echo 'Change DNS in resolv.conf'",
"os_info_id=$(grep ^ID= /etc/os-release | cut -d '=' -f2 | tr -d '\\\"')",
"if [ \"$os_info_id\" = \"rhel\" ] ; then nm_device_primary=$(ip route show default 0.0.0.0/0 | awk '/default/ {print $5}' | uniq) && nm_conn_primary=$(nmcli -t device show | grep 'CONNECTION' | sed 's/GENERAL.CONNECTION://') ; fi",
"if [ \"$os_info_id\" = \"rhel\" ] ; then nmcli device modify \"$nm_device_primary\" ipv4.ignore-auto-dns yes && nmcli connection modify \"$nm_conn_primary\" ipv4.ignore-auto-dns yes && systemctl reload NetworkManager ; fi",
"if [ -f /tmp/resolv.conf ]; then mkdir -p '/etc/dhcp/dhclient-enter-hooks.d' && mv /tmp/nodnsupdate /etc/dhcp/dhclient-enter-hooks.d/ ; fi",
"chmod +x /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate",
"if [ -f /tmp/resolv.conf ]; then mv /etc/resolv.conf /etc/resolv.conf.backup && mv /tmp/resolv.conf /etc/ ; fi",
"chmod 644 /etc/resolv.conf",
"chmod +x $HOME/terraform_dig.sh ; bash $HOME/terraform_dig.sh"
Expand Down

0 comments on commit 4bb1357

Please sign in to comment.