Browse Source

Adding fallback support for pyyaml.

Kenny Woodson 8 years ago
parent
commit
42af186c6f

+ 30 - 13
roles/lib_openshift/library/oadm_manage_node.py

@@ -334,7 +334,11 @@ class Yedit(object):
         if hasattr(self.yaml_dict, 'fa'):
             self.yaml_dict.fa.set_block_style()
 
-        Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        # pylint: disable=no-member
+        if hasattr(yaml, 'RoundTripDumper'):
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        else:
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, default_flow_style=False))
 
         return (True, self.yaml_dict)
 
@@ -374,7 +378,10 @@ class Yedit(object):
         # check if it is yaml
         try:
             if content_type == 'yaml' and contents:
-                self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                if hasattr(yaml, 'RoundTripLoader'):
+                    self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                else:
+                    self.yaml_dict = yaml.load(contents)
                 # pylint: disable=no-member
                 if hasattr(self.yaml_dict, 'fa'):
                     self.yaml_dict.fa.set_block_style()
@@ -542,12 +549,18 @@ class Yedit(object):
             return (False, self.yaml_dict)
 
         # deepcopy didn't work
-        tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
-                                                  default_flow_style=False),
-                             yaml.RoundTripLoader)
-        # pylint: disable=no-member
-        if hasattr(self.yaml_dict, 'fa'):
-            tmp_copy.fa.set_block_style()
+        if hasattr(yaml, 'round_trip_dump'):
+            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
+                                                      default_flow_style=False),
+                                 yaml.RoundTripLoader)
+
+            # pylint: disable=no-member
+            if hasattr(self.yaml_dict, 'fa'):
+                tmp_copy.fa.set_block_style()
+
+        else:
+            tmp_copy = copy.deepcopy(self.yaml_dict)
+
         result = Yedit.add_entry(tmp_copy, path, value, self.separator)
         if not result:
             return (False, self.yaml_dict)
@@ -560,11 +573,15 @@ class Yedit(object):
         ''' create a yaml file '''
         if not self.file_exists():
             # deepcopy didn't work
-            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
-                                 yaml.RoundTripLoader)
-            # pylint: disable=no-member
-            if hasattr(self.yaml_dict, 'fa'):
-                tmp_copy.fa.set_block_style()
+            if hasattr(yaml, 'round_trip_dump'):
+                tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
+                                     yaml.RoundTripLoader)
+                # pylint: disable=no-member
+                if hasattr(self.yaml_dict, 'fa'):
+                    tmp_copy.fa.set_block_style()
+            else:
+                tmp_copy = copy.deepcopy(self.yaml_dict)
+
             result = Yedit.add_entry(tmp_copy, path, value, self.separator)
             if result:
                 self.yaml_dict = tmp_copy

+ 30 - 13
roles/lib_openshift/library/oc_edit.py

@@ -362,7 +362,11 @@ class Yedit(object):
         if hasattr(self.yaml_dict, 'fa'):
             self.yaml_dict.fa.set_block_style()
 
-        Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        # pylint: disable=no-member
+        if hasattr(yaml, 'RoundTripDumper'):
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        else:
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, default_flow_style=False))
 
         return (True, self.yaml_dict)
 
@@ -402,7 +406,10 @@ class Yedit(object):
         # check if it is yaml
         try:
             if content_type == 'yaml' and contents:
-                self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                if hasattr(yaml, 'RoundTripLoader'):
+                    self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                else:
+                    self.yaml_dict = yaml.load(contents)
                 # pylint: disable=no-member
                 if hasattr(self.yaml_dict, 'fa'):
                     self.yaml_dict.fa.set_block_style()
@@ -570,12 +577,18 @@ class Yedit(object):
             return (False, self.yaml_dict)
 
         # deepcopy didn't work
-        tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
-                                                  default_flow_style=False),
-                             yaml.RoundTripLoader)
-        # pylint: disable=no-member
-        if hasattr(self.yaml_dict, 'fa'):
-            tmp_copy.fa.set_block_style()
+        if hasattr(yaml, 'round_trip_dump'):
+            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
+                                                      default_flow_style=False),
+                                 yaml.RoundTripLoader)
+
+            # pylint: disable=no-member
+            if hasattr(self.yaml_dict, 'fa'):
+                tmp_copy.fa.set_block_style()
+
+        else:
+            tmp_copy = copy.deepcopy(self.yaml_dict)
+
         result = Yedit.add_entry(tmp_copy, path, value, self.separator)
         if not result:
             return (False, self.yaml_dict)
@@ -588,11 +601,15 @@ class Yedit(object):
         ''' create a yaml file '''
         if not self.file_exists():
             # deepcopy didn't work
-            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
-                                 yaml.RoundTripLoader)
-            # pylint: disable=no-member
-            if hasattr(self.yaml_dict, 'fa'):
-                tmp_copy.fa.set_block_style()
+            if hasattr(yaml, 'round_trip_dump'):
+                tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
+                                     yaml.RoundTripLoader)
+                # pylint: disable=no-member
+                if hasattr(self.yaml_dict, 'fa'):
+                    tmp_copy.fa.set_block_style()
+            else:
+                tmp_copy = copy.deepcopy(self.yaml_dict)
+
             result = Yedit.add_entry(tmp_copy, path, value, self.separator)
             if result:
                 self.yaml_dict = tmp_copy

+ 30 - 13
roles/lib_openshift/library/oc_env.py

@@ -329,7 +329,11 @@ class Yedit(object):
         if hasattr(self.yaml_dict, 'fa'):
             self.yaml_dict.fa.set_block_style()
 
-        Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        # pylint: disable=no-member
+        if hasattr(yaml, 'RoundTripDumper'):
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        else:
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, default_flow_style=False))
 
         return (True, self.yaml_dict)
 
@@ -369,7 +373,10 @@ class Yedit(object):
         # check if it is yaml
         try:
             if content_type == 'yaml' and contents:
-                self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                if hasattr(yaml, 'RoundTripLoader'):
+                    self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                else:
+                    self.yaml_dict = yaml.load(contents)
                 # pylint: disable=no-member
                 if hasattr(self.yaml_dict, 'fa'):
                     self.yaml_dict.fa.set_block_style()
@@ -537,12 +544,18 @@ class Yedit(object):
             return (False, self.yaml_dict)
 
         # deepcopy didn't work
-        tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
-                                                  default_flow_style=False),
-                             yaml.RoundTripLoader)
-        # pylint: disable=no-member
-        if hasattr(self.yaml_dict, 'fa'):
-            tmp_copy.fa.set_block_style()
+        if hasattr(yaml, 'round_trip_dump'):
+            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
+                                                      default_flow_style=False),
+                                 yaml.RoundTripLoader)
+
+            # pylint: disable=no-member
+            if hasattr(self.yaml_dict, 'fa'):
+                tmp_copy.fa.set_block_style()
+
+        else:
+            tmp_copy = copy.deepcopy(self.yaml_dict)
+
         result = Yedit.add_entry(tmp_copy, path, value, self.separator)
         if not result:
             return (False, self.yaml_dict)
@@ -555,11 +568,15 @@ class Yedit(object):
         ''' create a yaml file '''
         if not self.file_exists():
             # deepcopy didn't work
-            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
-                                 yaml.RoundTripLoader)
-            # pylint: disable=no-member
-            if hasattr(self.yaml_dict, 'fa'):
-                tmp_copy.fa.set_block_style()
+            if hasattr(yaml, 'round_trip_dump'):
+                tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
+                                     yaml.RoundTripLoader)
+                # pylint: disable=no-member
+                if hasattr(self.yaml_dict, 'fa'):
+                    tmp_copy.fa.set_block_style()
+            else:
+                tmp_copy = copy.deepcopy(self.yaml_dict)
+
             result = Yedit.add_entry(tmp_copy, path, value, self.separator)
             if result:
                 self.yaml_dict = tmp_copy

+ 30 - 13
roles/lib_openshift/library/oc_label.py

@@ -338,7 +338,11 @@ class Yedit(object):
         if hasattr(self.yaml_dict, 'fa'):
             self.yaml_dict.fa.set_block_style()
 
-        Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        # pylint: disable=no-member
+        if hasattr(yaml, 'RoundTripDumper'):
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        else:
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, default_flow_style=False))
 
         return (True, self.yaml_dict)
 
@@ -378,7 +382,10 @@ class Yedit(object):
         # check if it is yaml
         try:
             if content_type == 'yaml' and contents:
-                self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                if hasattr(yaml, 'RoundTripLoader'):
+                    self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                else:
+                    self.yaml_dict = yaml.load(contents)
                 # pylint: disable=no-member
                 if hasattr(self.yaml_dict, 'fa'):
                     self.yaml_dict.fa.set_block_style()
@@ -546,12 +553,18 @@ class Yedit(object):
             return (False, self.yaml_dict)
 
         # deepcopy didn't work
-        tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
-                                                  default_flow_style=False),
-                             yaml.RoundTripLoader)
-        # pylint: disable=no-member
-        if hasattr(self.yaml_dict, 'fa'):
-            tmp_copy.fa.set_block_style()
+        if hasattr(yaml, 'round_trip_dump'):
+            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
+                                                      default_flow_style=False),
+                                 yaml.RoundTripLoader)
+
+            # pylint: disable=no-member
+            if hasattr(self.yaml_dict, 'fa'):
+                tmp_copy.fa.set_block_style()
+
+        else:
+            tmp_copy = copy.deepcopy(self.yaml_dict)
+
         result = Yedit.add_entry(tmp_copy, path, value, self.separator)
         if not result:
             return (False, self.yaml_dict)
@@ -564,11 +577,15 @@ class Yedit(object):
         ''' create a yaml file '''
         if not self.file_exists():
             # deepcopy didn't work
-            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
-                                 yaml.RoundTripLoader)
-            # pylint: disable=no-member
-            if hasattr(self.yaml_dict, 'fa'):
-                tmp_copy.fa.set_block_style()
+            if hasattr(yaml, 'round_trip_dump'):
+                tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
+                                     yaml.RoundTripLoader)
+                # pylint: disable=no-member
+                if hasattr(self.yaml_dict, 'fa'):
+                    tmp_copy.fa.set_block_style()
+            else:
+                tmp_copy = copy.deepcopy(self.yaml_dict)
+
             result = Yedit.add_entry(tmp_copy, path, value, self.separator)
             if result:
                 self.yaml_dict = tmp_copy

+ 30 - 13
roles/lib_openshift/library/oc_obj.py

@@ -341,7 +341,11 @@ class Yedit(object):
         if hasattr(self.yaml_dict, 'fa'):
             self.yaml_dict.fa.set_block_style()
 
-        Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        # pylint: disable=no-member
+        if hasattr(yaml, 'RoundTripDumper'):
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        else:
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, default_flow_style=False))
 
         return (True, self.yaml_dict)
 
@@ -381,7 +385,10 @@ class Yedit(object):
         # check if it is yaml
         try:
             if content_type == 'yaml' and contents:
-                self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                if hasattr(yaml, 'RoundTripLoader'):
+                    self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                else:
+                    self.yaml_dict = yaml.load(contents)
                 # pylint: disable=no-member
                 if hasattr(self.yaml_dict, 'fa'):
                     self.yaml_dict.fa.set_block_style()
@@ -549,12 +556,18 @@ class Yedit(object):
             return (False, self.yaml_dict)
 
         # deepcopy didn't work
-        tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
-                                                  default_flow_style=False),
-                             yaml.RoundTripLoader)
-        # pylint: disable=no-member
-        if hasattr(self.yaml_dict, 'fa'):
-            tmp_copy.fa.set_block_style()
+        if hasattr(yaml, 'round_trip_dump'):
+            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
+                                                      default_flow_style=False),
+                                 yaml.RoundTripLoader)
+
+            # pylint: disable=no-member
+            if hasattr(self.yaml_dict, 'fa'):
+                tmp_copy.fa.set_block_style()
+
+        else:
+            tmp_copy = copy.deepcopy(self.yaml_dict)
+
         result = Yedit.add_entry(tmp_copy, path, value, self.separator)
         if not result:
             return (False, self.yaml_dict)
@@ -567,11 +580,15 @@ class Yedit(object):
         ''' create a yaml file '''
         if not self.file_exists():
             # deepcopy didn't work
-            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
-                                 yaml.RoundTripLoader)
-            # pylint: disable=no-member
-            if hasattr(self.yaml_dict, 'fa'):
-                tmp_copy.fa.set_block_style()
+            if hasattr(yaml, 'round_trip_dump'):
+                tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
+                                     yaml.RoundTripLoader)
+                # pylint: disable=no-member
+                if hasattr(self.yaml_dict, 'fa'):
+                    tmp_copy.fa.set_block_style()
+            else:
+                tmp_copy = copy.deepcopy(self.yaml_dict)
+
             result = Yedit.add_entry(tmp_copy, path, value, self.separator)
             if result:
                 self.yaml_dict = tmp_copy

+ 30 - 13
roles/lib_openshift/library/oc_process.py

@@ -330,7 +330,11 @@ class Yedit(object):
         if hasattr(self.yaml_dict, 'fa'):
             self.yaml_dict.fa.set_block_style()
 
-        Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        # pylint: disable=no-member
+        if hasattr(yaml, 'RoundTripDumper'):
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        else:
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, default_flow_style=False))
 
         return (True, self.yaml_dict)
 
@@ -370,7 +374,10 @@ class Yedit(object):
         # check if it is yaml
         try:
             if content_type == 'yaml' and contents:
-                self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                if hasattr(yaml, 'RoundTripLoader'):
+                    self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                else:
+                    self.yaml_dict = yaml.load(contents)
                 # pylint: disable=no-member
                 if hasattr(self.yaml_dict, 'fa'):
                     self.yaml_dict.fa.set_block_style()
@@ -538,12 +545,18 @@ class Yedit(object):
             return (False, self.yaml_dict)
 
         # deepcopy didn't work
-        tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
-                                                  default_flow_style=False),
-                             yaml.RoundTripLoader)
-        # pylint: disable=no-member
-        if hasattr(self.yaml_dict, 'fa'):
-            tmp_copy.fa.set_block_style()
+        if hasattr(yaml, 'round_trip_dump'):
+            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
+                                                      default_flow_style=False),
+                                 yaml.RoundTripLoader)
+
+            # pylint: disable=no-member
+            if hasattr(self.yaml_dict, 'fa'):
+                tmp_copy.fa.set_block_style()
+
+        else:
+            tmp_copy = copy.deepcopy(self.yaml_dict)
+
         result = Yedit.add_entry(tmp_copy, path, value, self.separator)
         if not result:
             return (False, self.yaml_dict)
@@ -556,11 +569,15 @@ class Yedit(object):
         ''' create a yaml file '''
         if not self.file_exists():
             # deepcopy didn't work
-            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
-                                 yaml.RoundTripLoader)
-            # pylint: disable=no-member
-            if hasattr(self.yaml_dict, 'fa'):
-                tmp_copy.fa.set_block_style()
+            if hasattr(yaml, 'round_trip_dump'):
+                tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
+                                     yaml.RoundTripLoader)
+                # pylint: disable=no-member
+                if hasattr(self.yaml_dict, 'fa'):
+                    tmp_copy.fa.set_block_style()
+            else:
+                tmp_copy = copy.deepcopy(self.yaml_dict)
+
             result = Yedit.add_entry(tmp_copy, path, value, self.separator)
             if result:
                 self.yaml_dict = tmp_copy

+ 30 - 13
roles/lib_openshift/library/oc_route.py

@@ -372,7 +372,11 @@ class Yedit(object):
         if hasattr(self.yaml_dict, 'fa'):
             self.yaml_dict.fa.set_block_style()
 
-        Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        # pylint: disable=no-member
+        if hasattr(yaml, 'RoundTripDumper'):
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        else:
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, default_flow_style=False))
 
         return (True, self.yaml_dict)
 
@@ -412,7 +416,10 @@ class Yedit(object):
         # check if it is yaml
         try:
             if content_type == 'yaml' and contents:
-                self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                if hasattr(yaml, 'RoundTripLoader'):
+                    self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                else:
+                    self.yaml_dict = yaml.load(contents)
                 # pylint: disable=no-member
                 if hasattr(self.yaml_dict, 'fa'):
                     self.yaml_dict.fa.set_block_style()
@@ -580,12 +587,18 @@ class Yedit(object):
             return (False, self.yaml_dict)
 
         # deepcopy didn't work
-        tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
-                                                  default_flow_style=False),
-                             yaml.RoundTripLoader)
-        # pylint: disable=no-member
-        if hasattr(self.yaml_dict, 'fa'):
-            tmp_copy.fa.set_block_style()
+        if hasattr(yaml, 'round_trip_dump'):
+            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
+                                                      default_flow_style=False),
+                                 yaml.RoundTripLoader)
+
+            # pylint: disable=no-member
+            if hasattr(self.yaml_dict, 'fa'):
+                tmp_copy.fa.set_block_style()
+
+        else:
+            tmp_copy = copy.deepcopy(self.yaml_dict)
+
         result = Yedit.add_entry(tmp_copy, path, value, self.separator)
         if not result:
             return (False, self.yaml_dict)
@@ -598,11 +611,15 @@ class Yedit(object):
         ''' create a yaml file '''
         if not self.file_exists():
             # deepcopy didn't work
-            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
-                                 yaml.RoundTripLoader)
-            # pylint: disable=no-member
-            if hasattr(self.yaml_dict, 'fa'):
-                tmp_copy.fa.set_block_style()
+            if hasattr(yaml, 'round_trip_dump'):
+                tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
+                                     yaml.RoundTripLoader)
+                # pylint: disable=no-member
+                if hasattr(self.yaml_dict, 'fa'):
+                    tmp_copy.fa.set_block_style()
+            else:
+                tmp_copy = copy.deepcopy(self.yaml_dict)
+
             result = Yedit.add_entry(tmp_copy, path, value, self.separator)
             if result:
                 self.yaml_dict = tmp_copy

+ 30 - 13
roles/lib_openshift/library/oc_scale.py

@@ -316,7 +316,11 @@ class Yedit(object):
         if hasattr(self.yaml_dict, 'fa'):
             self.yaml_dict.fa.set_block_style()
 
-        Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        # pylint: disable=no-member
+        if hasattr(yaml, 'RoundTripDumper'):
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        else:
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, default_flow_style=False))
 
         return (True, self.yaml_dict)
 
@@ -356,7 +360,10 @@ class Yedit(object):
         # check if it is yaml
         try:
             if content_type == 'yaml' and contents:
-                self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                if hasattr(yaml, 'RoundTripLoader'):
+                    self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                else:
+                    self.yaml_dict = yaml.load(contents)
                 # pylint: disable=no-member
                 if hasattr(self.yaml_dict, 'fa'):
                     self.yaml_dict.fa.set_block_style()
@@ -524,12 +531,18 @@ class Yedit(object):
             return (False, self.yaml_dict)
 
         # deepcopy didn't work
-        tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
-                                                  default_flow_style=False),
-                             yaml.RoundTripLoader)
-        # pylint: disable=no-member
-        if hasattr(self.yaml_dict, 'fa'):
-            tmp_copy.fa.set_block_style()
+        if hasattr(yaml, 'round_trip_dump'):
+            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
+                                                      default_flow_style=False),
+                                 yaml.RoundTripLoader)
+
+            # pylint: disable=no-member
+            if hasattr(self.yaml_dict, 'fa'):
+                tmp_copy.fa.set_block_style()
+
+        else:
+            tmp_copy = copy.deepcopy(self.yaml_dict)
+
         result = Yedit.add_entry(tmp_copy, path, value, self.separator)
         if not result:
             return (False, self.yaml_dict)
@@ -542,11 +555,15 @@ class Yedit(object):
         ''' create a yaml file '''
         if not self.file_exists():
             # deepcopy didn't work
-            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
-                                 yaml.RoundTripLoader)
-            # pylint: disable=no-member
-            if hasattr(self.yaml_dict, 'fa'):
-                tmp_copy.fa.set_block_style()
+            if hasattr(yaml, 'round_trip_dump'):
+                tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
+                                     yaml.RoundTripLoader)
+                # pylint: disable=no-member
+                if hasattr(self.yaml_dict, 'fa'):
+                    tmp_copy.fa.set_block_style()
+            else:
+                tmp_copy = copy.deepcopy(self.yaml_dict)
+
             result = Yedit.add_entry(tmp_copy, path, value, self.separator)
             if result:
                 self.yaml_dict = tmp_copy

+ 30 - 13
roles/lib_openshift/library/oc_secret.py

@@ -362,7 +362,11 @@ class Yedit(object):
         if hasattr(self.yaml_dict, 'fa'):
             self.yaml_dict.fa.set_block_style()
 
-        Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        # pylint: disable=no-member
+        if hasattr(yaml, 'RoundTripDumper'):
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        else:
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, default_flow_style=False))
 
         return (True, self.yaml_dict)
 
@@ -402,7 +406,10 @@ class Yedit(object):
         # check if it is yaml
         try:
             if content_type == 'yaml' and contents:
-                self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                if hasattr(yaml, 'RoundTripLoader'):
+                    self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                else:
+                    self.yaml_dict = yaml.load(contents)
                 # pylint: disable=no-member
                 if hasattr(self.yaml_dict, 'fa'):
                     self.yaml_dict.fa.set_block_style()
@@ -570,12 +577,18 @@ class Yedit(object):
             return (False, self.yaml_dict)
 
         # deepcopy didn't work
-        tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
-                                                  default_flow_style=False),
-                             yaml.RoundTripLoader)
-        # pylint: disable=no-member
-        if hasattr(self.yaml_dict, 'fa'):
-            tmp_copy.fa.set_block_style()
+        if hasattr(yaml, 'round_trip_dump'):
+            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
+                                                      default_flow_style=False),
+                                 yaml.RoundTripLoader)
+
+            # pylint: disable=no-member
+            if hasattr(self.yaml_dict, 'fa'):
+                tmp_copy.fa.set_block_style()
+
+        else:
+            tmp_copy = copy.deepcopy(self.yaml_dict)
+
         result = Yedit.add_entry(tmp_copy, path, value, self.separator)
         if not result:
             return (False, self.yaml_dict)
@@ -588,11 +601,15 @@ class Yedit(object):
         ''' create a yaml file '''
         if not self.file_exists():
             # deepcopy didn't work
-            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
-                                 yaml.RoundTripLoader)
-            # pylint: disable=no-member
-            if hasattr(self.yaml_dict, 'fa'):
-                tmp_copy.fa.set_block_style()
+            if hasattr(yaml, 'round_trip_dump'):
+                tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
+                                     yaml.RoundTripLoader)
+                # pylint: disable=no-member
+                if hasattr(self.yaml_dict, 'fa'):
+                    tmp_copy.fa.set_block_style()
+            else:
+                tmp_copy = copy.deepcopy(self.yaml_dict)
+
             result = Yedit.add_entry(tmp_copy, path, value, self.separator)
             if result:
                 self.yaml_dict = tmp_copy

+ 30 - 13
roles/lib_openshift/library/oc_service.py

@@ -368,7 +368,11 @@ class Yedit(object):
         if hasattr(self.yaml_dict, 'fa'):
             self.yaml_dict.fa.set_block_style()
 
-        Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        # pylint: disable=no-member
+        if hasattr(yaml, 'RoundTripDumper'):
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        else:
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, default_flow_style=False))
 
         return (True, self.yaml_dict)
 
@@ -408,7 +412,10 @@ class Yedit(object):
         # check if it is yaml
         try:
             if content_type == 'yaml' and contents:
-                self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                if hasattr(yaml, 'RoundTripLoader'):
+                    self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                else:
+                    self.yaml_dict = yaml.load(contents)
                 # pylint: disable=no-member
                 if hasattr(self.yaml_dict, 'fa'):
                     self.yaml_dict.fa.set_block_style()
@@ -576,12 +583,18 @@ class Yedit(object):
             return (False, self.yaml_dict)
 
         # deepcopy didn't work
-        tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
-                                                  default_flow_style=False),
-                             yaml.RoundTripLoader)
-        # pylint: disable=no-member
-        if hasattr(self.yaml_dict, 'fa'):
-            tmp_copy.fa.set_block_style()
+        if hasattr(yaml, 'round_trip_dump'):
+            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
+                                                      default_flow_style=False),
+                                 yaml.RoundTripLoader)
+
+            # pylint: disable=no-member
+            if hasattr(self.yaml_dict, 'fa'):
+                tmp_copy.fa.set_block_style()
+
+        else:
+            tmp_copy = copy.deepcopy(self.yaml_dict)
+
         result = Yedit.add_entry(tmp_copy, path, value, self.separator)
         if not result:
             return (False, self.yaml_dict)
@@ -594,11 +607,15 @@ class Yedit(object):
         ''' create a yaml file '''
         if not self.file_exists():
             # deepcopy didn't work
-            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
-                                 yaml.RoundTripLoader)
-            # pylint: disable=no-member
-            if hasattr(self.yaml_dict, 'fa'):
-                tmp_copy.fa.set_block_style()
+            if hasattr(yaml, 'round_trip_dump'):
+                tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
+                                     yaml.RoundTripLoader)
+                # pylint: disable=no-member
+                if hasattr(self.yaml_dict, 'fa'):
+                    tmp_copy.fa.set_block_style()
+            else:
+                tmp_copy = copy.deepcopy(self.yaml_dict)
+
             result = Yedit.add_entry(tmp_copy, path, value, self.separator)
             if result:
                 self.yaml_dict = tmp_copy

+ 30 - 13
roles/lib_openshift/library/oc_serviceaccount.py

@@ -314,7 +314,11 @@ class Yedit(object):
         if hasattr(self.yaml_dict, 'fa'):
             self.yaml_dict.fa.set_block_style()
 
-        Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        # pylint: disable=no-member
+        if hasattr(yaml, 'RoundTripDumper'):
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        else:
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, default_flow_style=False))
 
         return (True, self.yaml_dict)
 
@@ -354,7 +358,10 @@ class Yedit(object):
         # check if it is yaml
         try:
             if content_type == 'yaml' and contents:
-                self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                if hasattr(yaml, 'RoundTripLoader'):
+                    self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                else:
+                    self.yaml_dict = yaml.load(contents)
                 # pylint: disable=no-member
                 if hasattr(self.yaml_dict, 'fa'):
                     self.yaml_dict.fa.set_block_style()
@@ -522,12 +529,18 @@ class Yedit(object):
             return (False, self.yaml_dict)
 
         # deepcopy didn't work
-        tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
-                                                  default_flow_style=False),
-                             yaml.RoundTripLoader)
-        # pylint: disable=no-member
-        if hasattr(self.yaml_dict, 'fa'):
-            tmp_copy.fa.set_block_style()
+        if hasattr(yaml, 'round_trip_dump'):
+            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
+                                                      default_flow_style=False),
+                                 yaml.RoundTripLoader)
+
+            # pylint: disable=no-member
+            if hasattr(self.yaml_dict, 'fa'):
+                tmp_copy.fa.set_block_style()
+
+        else:
+            tmp_copy = copy.deepcopy(self.yaml_dict)
+
         result = Yedit.add_entry(tmp_copy, path, value, self.separator)
         if not result:
             return (False, self.yaml_dict)
@@ -540,11 +553,15 @@ class Yedit(object):
         ''' create a yaml file '''
         if not self.file_exists():
             # deepcopy didn't work
-            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
-                                 yaml.RoundTripLoader)
-            # pylint: disable=no-member
-            if hasattr(self.yaml_dict, 'fa'):
-                tmp_copy.fa.set_block_style()
+            if hasattr(yaml, 'round_trip_dump'):
+                tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
+                                     yaml.RoundTripLoader)
+                # pylint: disable=no-member
+                if hasattr(self.yaml_dict, 'fa'):
+                    tmp_copy.fa.set_block_style()
+            else:
+                tmp_copy = copy.deepcopy(self.yaml_dict)
+
             result = Yedit.add_entry(tmp_copy, path, value, self.separator)
             if result:
                 self.yaml_dict = tmp_copy

+ 30 - 13
roles/lib_openshift/library/oc_serviceaccount_secret.py

@@ -314,7 +314,11 @@ class Yedit(object):
         if hasattr(self.yaml_dict, 'fa'):
             self.yaml_dict.fa.set_block_style()
 
-        Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        # pylint: disable=no-member
+        if hasattr(yaml, 'RoundTripDumper'):
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        else:
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, default_flow_style=False))
 
         return (True, self.yaml_dict)
 
@@ -354,7 +358,10 @@ class Yedit(object):
         # check if it is yaml
         try:
             if content_type == 'yaml' and contents:
-                self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                if hasattr(yaml, 'RoundTripLoader'):
+                    self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                else:
+                    self.yaml_dict = yaml.load(contents)
                 # pylint: disable=no-member
                 if hasattr(self.yaml_dict, 'fa'):
                     self.yaml_dict.fa.set_block_style()
@@ -522,12 +529,18 @@ class Yedit(object):
             return (False, self.yaml_dict)
 
         # deepcopy didn't work
-        tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
-                                                  default_flow_style=False),
-                             yaml.RoundTripLoader)
-        # pylint: disable=no-member
-        if hasattr(self.yaml_dict, 'fa'):
-            tmp_copy.fa.set_block_style()
+        if hasattr(yaml, 'round_trip_dump'):
+            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
+                                                      default_flow_style=False),
+                                 yaml.RoundTripLoader)
+
+            # pylint: disable=no-member
+            if hasattr(self.yaml_dict, 'fa'):
+                tmp_copy.fa.set_block_style()
+
+        else:
+            tmp_copy = copy.deepcopy(self.yaml_dict)
+
         result = Yedit.add_entry(tmp_copy, path, value, self.separator)
         if not result:
             return (False, self.yaml_dict)
@@ -540,11 +553,15 @@ class Yedit(object):
         ''' create a yaml file '''
         if not self.file_exists():
             # deepcopy didn't work
-            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
-                                 yaml.RoundTripLoader)
-            # pylint: disable=no-member
-            if hasattr(self.yaml_dict, 'fa'):
-                tmp_copy.fa.set_block_style()
+            if hasattr(yaml, 'round_trip_dump'):
+                tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
+                                     yaml.RoundTripLoader)
+                # pylint: disable=no-member
+                if hasattr(self.yaml_dict, 'fa'):
+                    tmp_copy.fa.set_block_style()
+            else:
+                tmp_copy = copy.deepcopy(self.yaml_dict)
+
             result = Yedit.add_entry(tmp_copy, path, value, self.separator)
             if result:
                 self.yaml_dict = tmp_copy

+ 30 - 13
roles/lib_openshift/library/oc_version.py

@@ -286,7 +286,11 @@ class Yedit(object):
         if hasattr(self.yaml_dict, 'fa'):
             self.yaml_dict.fa.set_block_style()
 
-        Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        # pylint: disable=no-member
+        if hasattr(yaml, 'RoundTripDumper'):
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        else:
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, default_flow_style=False))
 
         return (True, self.yaml_dict)
 
@@ -326,7 +330,10 @@ class Yedit(object):
         # check if it is yaml
         try:
             if content_type == 'yaml' and contents:
-                self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                if hasattr(yaml, 'RoundTripLoader'):
+                    self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                else:
+                    self.yaml_dict = yaml.load(contents)
                 # pylint: disable=no-member
                 if hasattr(self.yaml_dict, 'fa'):
                     self.yaml_dict.fa.set_block_style()
@@ -494,12 +501,18 @@ class Yedit(object):
             return (False, self.yaml_dict)
 
         # deepcopy didn't work
-        tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
-                                                  default_flow_style=False),
-                             yaml.RoundTripLoader)
-        # pylint: disable=no-member
-        if hasattr(self.yaml_dict, 'fa'):
-            tmp_copy.fa.set_block_style()
+        if hasattr(yaml, 'round_trip_dump'):
+            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
+                                                      default_flow_style=False),
+                                 yaml.RoundTripLoader)
+
+            # pylint: disable=no-member
+            if hasattr(self.yaml_dict, 'fa'):
+                tmp_copy.fa.set_block_style()
+
+        else:
+            tmp_copy = copy.deepcopy(self.yaml_dict)
+
         result = Yedit.add_entry(tmp_copy, path, value, self.separator)
         if not result:
             return (False, self.yaml_dict)
@@ -512,11 +525,15 @@ class Yedit(object):
         ''' create a yaml file '''
         if not self.file_exists():
             # deepcopy didn't work
-            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
-                                 yaml.RoundTripLoader)
-            # pylint: disable=no-member
-            if hasattr(self.yaml_dict, 'fa'):
-                tmp_copy.fa.set_block_style()
+            if hasattr(yaml, 'round_trip_dump'):
+                tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
+                                     yaml.RoundTripLoader)
+                # pylint: disable=no-member
+                if hasattr(self.yaml_dict, 'fa'):
+                    tmp_copy.fa.set_block_style()
+            else:
+                tmp_copy = copy.deepcopy(self.yaml_dict)
+
             result = Yedit.add_entry(tmp_copy, path, value, self.separator)
             if result:
                 self.yaml_dict = tmp_copy

+ 14 - 4
roles/lib_openshift/src/test/unit/oc_route.py

@@ -35,8 +35,9 @@ class OCRouteTest(unittest.TestCase):
         ''' setup method will create a file and set to known configuration '''
         pass
 
+    @mock.patch('oc_route.Utils.create_tmpfile_copy')
     @mock.patch('oc_route.OCRoute._run')
-    def test_list_route(self, mock_cmd):
+    def test_list_route(self, mock_cmd, mock_tmpfile_copy):
         ''' Testing getting a route '''
 
         # Arrange
@@ -114,6 +115,10 @@ class OCRouteTest(unittest.TestCase):
             (0, route_result, ''),
         ]
 
+        mock_tmpfile_copy.side_effect = [
+            '/tmp/mock.kubeconfig',
+        ]
+
         # Act
         results = OCRoute.run_ansible(params, False)
 
@@ -127,11 +132,11 @@ class OCRouteTest(unittest.TestCase):
             mock.call(['oc', '-n', 'default', 'get', 'route', 'test', '-o', 'json'], None),
         ])
 
+    @mock.patch('oc_route.Utils.create_tmpfile_copy')
     @mock.patch('oc_route.Yedit._write')
     @mock.patch('oc_route.OCRoute._run')
-    def test_create_route(self, mock_cmd, mock_write):
+    def test_create_route(self, mock_cmd, mock_write, mock_tmpfile_copy):
         ''' Testing getting a route '''
-
         # Arrange
 
         # run_ansible input parameters
@@ -230,6 +235,10 @@ metadata:
             (0, route_result, ''),
         ]
 
+        mock_tmpfile_copy.side_effect = [
+            '/tmp/mock.kubeconfig',
+        ]
+
         mock_write.assert_has_calls = [
             # First call to mock
             mock.call('/tmp/test', test_route)
@@ -246,7 +255,8 @@ metadata:
         # Making sure our mock was called as we expected
         mock_cmd.assert_has_calls([
             mock.call(['oc', '-n', 'default', 'get', 'route', 'test', '-o', 'json'], None),
-            mock.call(['oc', '-n', 'default', 'create', '-f', '/tmp/test'], None),
+            mock.call(['oc', '-n', 'default', 'create', '-f', mock.ANY], None),
+            mock.call(['oc', '-n', 'default', 'get', 'route', 'test', '-o', 'json'], None),
         ])
 
     def tearDown(self):

+ 7 - 2
roles/lib_utils/library/repoquery.py

@@ -29,13 +29,18 @@
 # pylint: disable=wrong-import-order,wrong-import-position,unused-import
 
 from __future__ import print_function  # noqa: F401
+import copy  # noqa: F401
 import json  # noqa: F401
 import os  # noqa: F401
 import re  # noqa: F401
-# pylint: disable=import-error
-import ruamel.yaml as yaml  # noqa: F401
 import shutil  # noqa: F401
 
+# pylint: disable=import-error
+try:
+    import ruamel.yaml as yaml  # noqa: F401
+except ImportError:
+    import yaml
+
 from ansible.module_utils.basic import AnsibleModule
 
 # -*- -*- -*- End included fragment: lib/import.py -*- -*- -*-

+ 37 - 15
roles/lib_utils/library/yedit.py

@@ -29,13 +29,18 @@
 # pylint: disable=wrong-import-order,wrong-import-position,unused-import
 
 from __future__ import print_function  # noqa: F401
+import copy  # noqa: F401
 import json  # noqa: F401
 import os  # noqa: F401
 import re  # noqa: F401
-# pylint: disable=import-error
-import ruamel.yaml as yaml  # noqa: F401
 import shutil  # noqa: F401
 
+# pylint: disable=import-error
+try:
+    import ruamel.yaml as yaml  # noqa: F401
+except ImportError:
+    import yaml
+
 from ansible.module_utils.basic import AnsibleModule
 
 # -*- -*- -*- End included fragment: lib/import.py -*- -*- -*-
@@ -379,7 +384,11 @@ class Yedit(object):
         if hasattr(self.yaml_dict, 'fa'):
             self.yaml_dict.fa.set_block_style()
 
-        Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        # pylint: disable=no-member
+        if hasattr(yaml, 'RoundTripDumper'):
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        else:
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, default_flow_style=False))
 
         return (True, self.yaml_dict)
 
@@ -419,7 +428,10 @@ class Yedit(object):
         # check if it is yaml
         try:
             if content_type == 'yaml' and contents:
-                self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                if hasattr(yaml, 'RoundTripLoader'):
+                    self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                else:
+                    self.yaml_dict = yaml.load(contents)
                 # pylint: disable=no-member
                 if hasattr(self.yaml_dict, 'fa'):
                     self.yaml_dict.fa.set_block_style()
@@ -587,12 +599,18 @@ class Yedit(object):
             return (False, self.yaml_dict)
 
         # deepcopy didn't work
-        tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
-                                                  default_flow_style=False),
-                             yaml.RoundTripLoader)
-        # pylint: disable=no-member
-        if hasattr(self.yaml_dict, 'fa'):
-            tmp_copy.fa.set_block_style()
+        if hasattr(yaml, 'round_trip_dump'):
+            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
+                                                      default_flow_style=False),
+                                 yaml.RoundTripLoader)
+
+            # pylint: disable=no-member
+            if hasattr(self.yaml_dict, 'fa'):
+                tmp_copy.fa.set_block_style()
+
+        else:
+            tmp_copy = copy.deepcopy(self.yaml_dict)
+
         result = Yedit.add_entry(tmp_copy, path, value, self.separator)
         if not result:
             return (False, self.yaml_dict)
@@ -605,11 +623,15 @@ class Yedit(object):
         ''' create a yaml file '''
         if not self.file_exists():
             # deepcopy didn't work
-            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
-                                 yaml.RoundTripLoader)
-            # pylint: disable=no-member
-            if hasattr(self.yaml_dict, 'fa'):
-                tmp_copy.fa.set_block_style()
+            if hasattr(yaml, 'round_trip_dump'):
+                tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
+                                     yaml.RoundTripLoader)
+                # pylint: disable=no-member
+                if hasattr(self.yaml_dict, 'fa'):
+                    tmp_copy.fa.set_block_style()
+            else:
+                tmp_copy = copy.deepcopy(self.yaml_dict)
+
             result = Yedit.add_entry(tmp_copy, path, value, self.separator)
             if result:
                 self.yaml_dict = tmp_copy

+ 30 - 13
roles/lib_utils/src/class/yedit.py

@@ -198,7 +198,11 @@ class Yedit(object):
         if hasattr(self.yaml_dict, 'fa'):
             self.yaml_dict.fa.set_block_style()
 
-        Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        # pylint: disable=no-member
+        if hasattr(yaml, 'RoundTripDumper'):
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+        else:
+            Yedit._write(self.filename, yaml.dump(self.yaml_dict, default_flow_style=False))
 
         return (True, self.yaml_dict)
 
@@ -238,7 +242,10 @@ class Yedit(object):
         # check if it is yaml
         try:
             if content_type == 'yaml' and contents:
-                self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                if hasattr(yaml, 'RoundTripLoader'):
+                    self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+                else:
+                    self.yaml_dict = yaml.load(contents)
                 # pylint: disable=no-member
                 if hasattr(self.yaml_dict, 'fa'):
                     self.yaml_dict.fa.set_block_style()
@@ -406,12 +413,18 @@ class Yedit(object):
             return (False, self.yaml_dict)
 
         # deepcopy didn't work
-        tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
-                                                  default_flow_style=False),
-                             yaml.RoundTripLoader)
-        # pylint: disable=no-member
-        if hasattr(self.yaml_dict, 'fa'):
-            tmp_copy.fa.set_block_style()
+        if hasattr(yaml, 'round_trip_dump'):
+            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
+                                                      default_flow_style=False),
+                                 yaml.RoundTripLoader)
+
+            # pylint: disable=no-member
+            if hasattr(self.yaml_dict, 'fa'):
+                tmp_copy.fa.set_block_style()
+
+        else:
+            tmp_copy = copy.deepcopy(self.yaml_dict)
+
         result = Yedit.add_entry(tmp_copy, path, value, self.separator)
         if not result:
             return (False, self.yaml_dict)
@@ -424,11 +437,15 @@ class Yedit(object):
         ''' create a yaml file '''
         if not self.file_exists():
             # deepcopy didn't work
-            tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
-                                 yaml.RoundTripLoader)
-            # pylint: disable=no-member
-            if hasattr(self.yaml_dict, 'fa'):
-                tmp_copy.fa.set_block_style()
+            if hasattr(yaml, 'round_trip_dump'):
+                tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False),  # noqa: E501
+                                     yaml.RoundTripLoader)
+                # pylint: disable=no-member
+                if hasattr(self.yaml_dict, 'fa'):
+                    tmp_copy.fa.set_block_style()
+            else:
+                tmp_copy = copy.deepcopy(self.yaml_dict)
+
             result = Yedit.add_entry(tmp_copy, path, value, self.separator)
             if result:
                 self.yaml_dict = tmp_copy

+ 7 - 2
roles/lib_utils/src/lib/import.py

@@ -4,11 +4,16 @@
 # pylint: disable=wrong-import-order,wrong-import-position,unused-import
 
 from __future__ import print_function  # noqa: F401
+import copy  # noqa: F401
 import json  # noqa: F401
 import os  # noqa: F401
 import re  # noqa: F401
-# pylint: disable=import-error
-import ruamel.yaml as yaml  # noqa: F401
 import shutil  # noqa: F401
 
+# pylint: disable=import-error
+try:
+    import ruamel.yaml as yaml  # noqa: F401
+except ImportError:
+    import yaml
+
 from ansible.module_utils.basic import AnsibleModule