From cf30836645473c62599e838ab48b2d31677fa584 Mon Sep 17 00:00:00 2001
From: Ryan Harper <ryan.harper@canonical.com>
Date: Thu, 7 Feb 2019 22:38:41 +0000
Subject: netplan: Don't render yaml aliases when dumping netplan

Cloud-init rendered netplan with duplicate aliases if a network config
included "global" nameserver/search values.  Netplan uses can read yaml
files which do use aliaes but cloud-init did not render a single yaml
dictionary, instead it combined yaml sections into a single document
which sometimes resulted in duplicate aliases being present.

This branch introduces a yaml SafeDumper class which can set the
'ignore_aliases' attribute.  This is not enabled by default but callers
to util.yaml_dumps can pass a boolean to toggle this.  The netplan
render uses noalias=True and the resulting yaml output does not contain
any aliases.

LP: #1815051
---
 cloudinit/net/netplan.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

(limited to 'cloudinit/net')

diff --git a/cloudinit/net/netplan.py b/cloudinit/net/netplan.py
index 21517fda..e54a34e5 100644
--- a/cloudinit/net/netplan.py
+++ b/cloudinit/net/netplan.py
@@ -361,7 +361,8 @@ class Renderer(renderer.Renderer):
             if section:
                 dump = util.yaml_dumps({name: section},
                                        explicit_start=False,
-                                       explicit_end=False)
+                                       explicit_end=False,
+                                       noalias=True)
                 txt = util.indent(dump, ' ' * 4)
                 return [txt]
             return []
-- 
cgit v1.2.3