diff options
Diffstat (limited to 'roles')
57 files changed, 1001 insertions, 326 deletions
diff --git a/roles/container_runtime/defaults/main.yml b/roles/container_runtime/defaults/main.yml index 01540776f..77cf86b0a 100644 --- a/roles/container_runtime/defaults/main.yml +++ b/roles/container_runtime/defaults/main.yml @@ -87,6 +87,8 @@ openshift_use_crio_only: False l_openshift_image_tag_default: "{{ openshift_release | default('latest') }}" l_openshift_image_tag: "{{ openshift_image_tag | default(l_openshift_image_tag_default) | string}}" +l_required_docker_version: '1.12' + # --------------------- # # systemcontainers_crio # # --------------------- # diff --git a/roles/container_runtime/tasks/docker_upgrade_check.yml b/roles/container_runtime/tasks/docker_upgrade_check.yml index 8dd916e79..4a341b744 100644 --- a/roles/container_runtime/tasks/docker_upgrade_check.yml +++ b/roles/container_runtime/tasks/docker_upgrade_check.yml @@ -36,14 +36,16 @@ failed_when: false changed_when: false -- fail: - msg: This playbook requires access to Docker 1.12 or later +- name: Required docker version not available (non-atomic) + fail: + msg: "This playbook requires access to Docker {{ l_required_docker_version }} or later" # Disable the 1.12 requirement if the user set a specific Docker version when: - not openshift_is_atomic | bool - docker_version is not defined - - docker_upgrade is not defined or docker_upgrade | bool == True - - (pkg_check.rc == 0 and (avail_docker_version.stdout == "" or avail_docker_version.stdout is version_compare('1.12','<'))) + - docker_upgrade | bool + - pkg_check.rc == 0 + - avail_docker_version.stdout == "" or avail_docker_version.stdout is version_compare(l_required_docker_version,'<') # Default l_docker_upgrade to False, we'll set to True if an upgrade is required: - set_fact: @@ -54,7 +56,8 @@ docker_version: "{{ avail_docker_version.stdout }}" when: - not openshift_is_atomic | bool - - pkg_check.rc == 0 and docker_version is not defined + - pkg_check.rc == 0 + - docker_version is not defined - name: Flag for Docker upgrade if necessary set_fact: @@ -74,8 +77,9 @@ l_docker_version: "{{ g_atomic_docker_version_result.stdout | from_yaml }}" when: openshift_is_atomic | bool -- fail: - msg: This playbook requires access to Docker 1.12 or later +- name: Required docker version is unavailable (atomic) + fail: + msg: "This playbook requires access to Docker {{ l_required_docker_version }} or later" when: - openshift_is_atomic | bool - - l_docker_version.avail_version | default(l_docker_version.curr_version, true) is version_compare('1.12','<') + - l_docker_version.avail_version | default(l_docker_version.curr_version, true) is version_compare(l_required_docker_version,'<') diff --git a/roles/lib_openshift/library/oc_adm_ca_server_cert.py b/roles/lib_openshift/library/oc_adm_ca_server_cert.py index bfed58011..379d9a83e 100644 --- a/roles/lib_openshift/library/oc_adm_ca_server_cert.py +++ b/roles/lib_openshift/library/oc_adm_ca_server_cert.py @@ -362,10 +362,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -413,7 +419,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -658,7 +664,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -727,6 +738,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_adm_csr.py b/roles/lib_openshift/library/oc_adm_csr.py index c78e379d5..30e8991cd 100644 --- a/roles/lib_openshift/library/oc_adm_csr.py +++ b/roles/lib_openshift/library/oc_adm_csr.py @@ -340,10 +340,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -391,7 +397,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -636,7 +642,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -705,6 +716,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] @@ -1639,6 +1651,7 @@ def main(): timeout=dict(default=30, type='int'), approve_all=dict(default=False, type='bool'), service_account=dict(default='node-bootstrapper', type='str'), + fail_on_timeout=dict(default=False, type='bool'), ), supports_check_mode=True, mutually_exclusive=[['approve_all', 'nodes']], @@ -1649,6 +1662,12 @@ def main(): rval = OCcsr.run_ansible(module.params, module.check_mode) + # If we timed out then we weren't finished. Fail if user requested to fail. + if (module.params['timeout'] > 0 and + module.params['fail_on_timeout'] and + rval['timeout']): + return module.fail_json(msg='Timed out accepting certificate signing requests. Failing as requested.', **rval) + if 'failed' in rval: return module.fail_json(**rval) diff --git a/roles/lib_openshift/library/oc_adm_manage_node.py b/roles/lib_openshift/library/oc_adm_manage_node.py index b1b2cb5b5..1cf5b4953 100644 --- a/roles/lib_openshift/library/oc_adm_manage_node.py +++ b/roles/lib_openshift/library/oc_adm_manage_node.py @@ -348,10 +348,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -399,7 +405,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -644,7 +650,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -713,6 +724,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_adm_policy_group.py b/roles/lib_openshift/library/oc_adm_policy_group.py index 2773201d7..70a82aaf6 100644 --- a/roles/lib_openshift/library/oc_adm_policy_group.py +++ b/roles/lib_openshift/library/oc_adm_policy_group.py @@ -334,10 +334,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -385,7 +391,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -630,7 +636,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -699,6 +710,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_adm_policy_user.py b/roles/lib_openshift/library/oc_adm_policy_user.py index 25cbed8b7..6796d7475 100644 --- a/roles/lib_openshift/library/oc_adm_policy_user.py +++ b/roles/lib_openshift/library/oc_adm_policy_user.py @@ -348,10 +348,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -399,7 +405,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -644,7 +650,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -713,6 +724,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_adm_registry.py b/roles/lib_openshift/library/oc_adm_registry.py index e26214316..8b1e9e04f 100644 --- a/roles/lib_openshift/library/oc_adm_registry.py +++ b/roles/lib_openshift/library/oc_adm_registry.py @@ -452,10 +452,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -503,7 +509,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -748,7 +754,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -817,6 +828,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_adm_router.py b/roles/lib_openshift/library/oc_adm_router.py index 62fca19e5..c1d19ff88 100644 --- a/roles/lib_openshift/library/oc_adm_router.py +++ b/roles/lib_openshift/library/oc_adm_router.py @@ -477,10 +477,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -528,7 +534,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -773,7 +779,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -842,6 +853,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_clusterrole.py b/roles/lib_openshift/library/oc_clusterrole.py index 0c4bfa01f..884ed706f 100644 --- a/roles/lib_openshift/library/oc_clusterrole.py +++ b/roles/lib_openshift/library/oc_clusterrole.py @@ -326,10 +326,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -377,7 +383,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -622,7 +628,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -691,6 +702,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_configmap.py b/roles/lib_openshift/library/oc_configmap.py index 36e6111eb..f188ed2fe 100644 --- a/roles/lib_openshift/library/oc_configmap.py +++ b/roles/lib_openshift/library/oc_configmap.py @@ -332,10 +332,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -383,7 +389,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -628,7 +634,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -697,6 +708,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_edit.py b/roles/lib_openshift/library/oc_edit.py index ab4f153c7..bfb7c5908 100644 --- a/roles/lib_openshift/library/oc_edit.py +++ b/roles/lib_openshift/library/oc_edit.py @@ -376,10 +376,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -427,7 +433,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -672,7 +678,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -741,6 +752,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_env.py b/roles/lib_openshift/library/oc_env.py index f334ddaa4..d57bea625 100644 --- a/roles/lib_openshift/library/oc_env.py +++ b/roles/lib_openshift/library/oc_env.py @@ -343,10 +343,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -394,7 +400,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -639,7 +645,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -708,6 +719,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_group.py b/roles/lib_openshift/library/oc_group.py index 7e9078339..ef01d01d7 100644 --- a/roles/lib_openshift/library/oc_group.py +++ b/roles/lib_openshift/library/oc_group.py @@ -316,10 +316,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -367,7 +373,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -612,7 +618,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -681,6 +692,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_image.py b/roles/lib_openshift/library/oc_image.py index e71e2eb5c..b479857ad 100644 --- a/roles/lib_openshift/library/oc_image.py +++ b/roles/lib_openshift/library/oc_image.py @@ -335,10 +335,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -386,7 +392,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -631,7 +637,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -700,6 +711,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_label.py b/roles/lib_openshift/library/oc_label.py index ac3279ef8..93c11970e 100644 --- a/roles/lib_openshift/library/oc_label.py +++ b/roles/lib_openshift/library/oc_label.py @@ -352,10 +352,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -403,7 +409,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -648,7 +654,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -717,6 +728,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_obj.py b/roles/lib_openshift/library/oc_obj.py index ca53c4c97..0512cd34e 100644 --- a/roles/lib_openshift/library/oc_obj.py +++ b/roles/lib_openshift/library/oc_obj.py @@ -355,10 +355,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -406,7 +412,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -651,7 +657,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -720,6 +731,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_objectvalidator.py b/roles/lib_openshift/library/oc_objectvalidator.py index 877c78d93..24da3e639 100644 --- a/roles/lib_openshift/library/oc_objectvalidator.py +++ b/roles/lib_openshift/library/oc_objectvalidator.py @@ -287,10 +287,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -338,7 +344,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -583,7 +589,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -652,6 +663,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_process.py b/roles/lib_openshift/library/oc_process.py index 507170424..30b60ebc5 100644 --- a/roles/lib_openshift/library/oc_process.py +++ b/roles/lib_openshift/library/oc_process.py @@ -344,10 +344,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -395,7 +401,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -640,7 +646,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -709,6 +720,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_project.py b/roles/lib_openshift/library/oc_project.py index 347e879ca..7b8ca4a59 100644 --- a/roles/lib_openshift/library/oc_project.py +++ b/roles/lib_openshift/library/oc_project.py @@ -341,10 +341,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -392,7 +398,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -637,7 +643,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -706,6 +717,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_pvc.py b/roles/lib_openshift/library/oc_pvc.py index 93c96b817..342865048 100644 --- a/roles/lib_openshift/library/oc_pvc.py +++ b/roles/lib_openshift/library/oc_pvc.py @@ -348,10 +348,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -399,7 +405,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -644,7 +650,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -713,6 +724,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_route.py b/roles/lib_openshift/library/oc_route.py index 3369cf134..5106925b4 100644 --- a/roles/lib_openshift/library/oc_route.py +++ b/roles/lib_openshift/library/oc_route.py @@ -392,10 +392,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -443,7 +449,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -688,7 +694,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -757,6 +768,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_scale.py b/roles/lib_openshift/library/oc_scale.py index 1b6202a26..d07c0fc2e 100644 --- a/roles/lib_openshift/library/oc_scale.py +++ b/roles/lib_openshift/library/oc_scale.py @@ -330,10 +330,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -381,7 +387,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -626,7 +632,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -695,6 +706,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_secret.py b/roles/lib_openshift/library/oc_secret.py index 732299e48..998daae1a 100644 --- a/roles/lib_openshift/library/oc_secret.py +++ b/roles/lib_openshift/library/oc_secret.py @@ -388,10 +388,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -439,7 +445,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -684,7 +690,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -753,6 +764,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_service.py b/roles/lib_openshift/library/oc_service.py index a6cf764ff..81977b590 100644 --- a/roles/lib_openshift/library/oc_service.py +++ b/roles/lib_openshift/library/oc_service.py @@ -395,10 +395,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -446,7 +452,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -691,7 +697,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -760,6 +771,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_serviceaccount.py b/roles/lib_openshift/library/oc_serviceaccount.py index 90d514292..db997ef9c 100644 --- a/roles/lib_openshift/library/oc_serviceaccount.py +++ b/roles/lib_openshift/library/oc_serviceaccount.py @@ -328,10 +328,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -379,7 +385,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -624,7 +630,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -693,6 +704,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_serviceaccount_secret.py b/roles/lib_openshift/library/oc_serviceaccount_secret.py index 0d9acac0e..7ad380631 100644 --- a/roles/lib_openshift/library/oc_serviceaccount_secret.py +++ b/roles/lib_openshift/library/oc_serviceaccount_secret.py @@ -328,10 +328,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -379,7 +385,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -624,7 +630,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -693,6 +704,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_storageclass.py b/roles/lib_openshift/library/oc_storageclass.py index 6fb5a94e9..401572536 100644 --- a/roles/lib_openshift/library/oc_storageclass.py +++ b/roles/lib_openshift/library/oc_storageclass.py @@ -346,10 +346,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -397,7 +403,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -642,7 +648,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -711,6 +722,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_user.py b/roles/lib_openshift/library/oc_user.py index feb69348b..4e653fc47 100644 --- a/roles/lib_openshift/library/oc_user.py +++ b/roles/lib_openshift/library/oc_user.py @@ -388,10 +388,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -439,7 +445,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -684,7 +690,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -753,6 +764,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_version.py b/roles/lib_openshift/library/oc_version.py index 0f024c048..b918f180c 100644 --- a/roles/lib_openshift/library/oc_version.py +++ b/roles/lib_openshift/library/oc_version.py @@ -300,10 +300,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -351,7 +357,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -596,7 +602,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -665,6 +676,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/library/oc_volume.py b/roles/lib_openshift/library/oc_volume.py index 6f409f979..f20546969 100644 --- a/roles/lib_openshift/library/oc_volume.py +++ b/roles/lib_openshift/library/oc_volume.py @@ -377,10 +377,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -428,7 +434,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -673,7 +679,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -742,6 +753,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/lib_openshift/src/ansible/oc_adm_csr.py b/roles/lib_openshift/src/ansible/oc_adm_csr.py index 9e43a810b..7b5e245d4 100644 --- a/roles/lib_openshift/src/ansible/oc_adm_csr.py +++ b/roles/lib_openshift/src/ansible/oc_adm_csr.py @@ -16,6 +16,7 @@ def main(): timeout=dict(default=30, type='int'), approve_all=dict(default=False, type='bool'), service_account=dict(default='node-bootstrapper', type='str'), + fail_on_timeout=dict(default=False, type='bool'), ), supports_check_mode=True, mutually_exclusive=[['approve_all', 'nodes']], @@ -26,6 +27,12 @@ def main(): rval = OCcsr.run_ansible(module.params, module.check_mode) + # If we timed out then we weren't finished. Fail if user requested to fail. + if (module.params['timeout'] > 0 and + module.params['fail_on_timeout'] and + rval['timeout']): + return module.fail_json(msg='Timed out accepting certificate signing requests. Failing as requested.', **rval) + if 'failed' in rval: return module.fail_json(**rval) diff --git a/roles/lib_utils/action_plugins/generate_pv_pvcs_list.py b/roles/lib_utils/action_plugins/generate_pv_pvcs_list.py index eb13a58ba..c60742dd3 100644 --- a/roles/lib_utils/action_plugins/generate_pv_pvcs_list.py +++ b/roles/lib_utils/action_plugins/generate_pv_pvcs_list.py @@ -118,10 +118,16 @@ class ActionModule(ActionBase): create_pvc = self._templar.template(create_pvc) if kind != 'object' and create_pv and create_pvc: volume, size, _, access_modes = self.build_common(varname=varname) + storageclass = self.task_vars.get(str(varname) + '_storageclass') + if storageclass: + storageclass = self._templar.template(storageclass) + elif storageclass is None and kind != 'dynamic': + storageclass = '' return dict( name="{0}-claim".format(volume), capacity=size, - access_modes=access_modes) + access_modes=access_modes, + storageclass=storageclass) return None def run(self, tmp=None, task_vars=None): diff --git a/roles/lib_utils/action_plugins/sanity_checks.py b/roles/lib_utils/action_plugins/sanity_checks.py index 09ce55e8f..ce54debc2 100644 --- a/roles/lib_utils/action_plugins/sanity_checks.py +++ b/roles/lib_utils/action_plugins/sanity_checks.py @@ -54,6 +54,12 @@ class ActionModule(ActionBase): def template_var(self, hostvars, host, varname): """Retrieve a variable from hostvars and template it. If undefined, return None type.""" + # We will set the current host and variable checked for easy debugging + # if there are any unhandled exceptions. + # pylint: disable=W0201 + self.last_checked_var = varname + # pylint: disable=W0201 + self.last_checked_host = host res = hostvars[host].get(varname) if res is None: return None @@ -156,6 +162,11 @@ class ActionModule(ActionBase): # pylint: disable=W0201 self.task_vars = task_vars or {} + # pylint: disable=W0201 + self.last_checked_host = "none" + # pylint: disable=W0201 + self.last_checked_var = "none" + # self._task.args holds task parameters. # check_hosts is a parameter to this plugin, and should provide # a list of hosts. @@ -172,7 +183,13 @@ class ActionModule(ActionBase): # We loop through each host in the provided list check_hosts for host in check_hosts: - self.run_checks(hostvars, host) + try: + self.run_checks(hostvars, host) + except Exception as uncaught_e: + msg = "last_checked_host: {}, last_checked_var: {};" + msg = msg.format(self.last_checked_host, self.last_checked_var) + msg += str(uncaught_e) + raise errors.AnsibleModuleError(msg) result["changed"] = False result["failed"] = False diff --git a/roles/lib_utils/library/yedit.py b/roles/lib_utils/library/yedit.py index cf5c2e423..4bd5171a7 100644 --- a/roles/lib_utils/library/yedit.py +++ b/roles/lib_utils/library/yedit.py @@ -410,10 +410,16 @@ class Yedit(object): pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -461,7 +467,7 @@ class Yedit(object): # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -706,7 +712,12 @@ class Yedit(object): curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -775,6 +786,7 @@ class Yedit(object): '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] @@ -885,7 +897,7 @@ def main(): debug=dict(default=False, type='bool'), src=dict(default=None, type='str'), content=dict(default=None), - content_type=dict(default='dict', choices=['dict']), + content_type=dict(default='yaml', choices=['yaml', 'json']), key=dict(default='', type='str'), value=dict(), value_type=dict(default='', type='str'), diff --git a/roles/lib_utils/src/ansible/yedit.py b/roles/lib_utils/src/ansible/yedit.py index c4b818cf1..c2ae08654 100644 --- a/roles/lib_utils/src/ansible/yedit.py +++ b/roles/lib_utils/src/ansible/yedit.py @@ -13,7 +13,7 @@ def main(): debug=dict(default=False, type='bool'), src=dict(default=None, type='str'), content=dict(default=None), - content_type=dict(default='dict', choices=['dict']), + content_type=dict(default='yaml', choices=['yaml', 'json']), key=dict(default='', type='str'), value=dict(), value_type=dict(default='', type='str'), diff --git a/roles/lib_utils/src/class/yedit.py b/roles/lib_utils/src/class/yedit.py index 0a4fbe07a..5f69d797c 100644 --- a/roles/lib_utils/src/class/yedit.py +++ b/roles/lib_utils/src/class/yedit.py @@ -207,10 +207,16 @@ class Yedit(object): pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -258,7 +264,7 @@ class Yedit(object): # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -503,7 +509,12 @@ class Yedit(object): curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -572,6 +583,7 @@ class Yedit(object): '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] diff --git a/roles/openshift_aws/tasks/accept_nodes.yml b/roles/openshift_aws/tasks/accept_nodes.yml index db30fe5c9..cc0cdcb0b 100644 --- a/roles/openshift_aws/tasks/accept_nodes.yml +++ b/roles/openshift_aws/tasks/accept_nodes.yml @@ -37,5 +37,6 @@ #approve_all: True nodes: "{{ instancesout.instances|map(attribute='private_dns_name') | list }}" timeout: 60 + fail_on_timeout: "{{ openshift_aws_node_accept_fail_on_timeout | default(false) | bool }}" register: nodeout delegate_to: "{{ groups.masters.0 }}" diff --git a/roles/openshift_cloud_provider/defaults/main.yml b/roles/openshift_cloud_provider/defaults/main.yml index 37cbf5603..cda6acd90 100644 --- a/roles/openshift_cloud_provider/defaults/main.yml +++ b/roles/openshift_cloud_provider/defaults/main.yml @@ -2,3 +2,4 @@ openshift_gcp_project: '' openshift_gcp_prefix: '' openshift_gcp_network_name: "{{ openshift_gcp_prefix }}network" +openshift_gcp_multizone: False diff --git a/roles/openshift_cloud_provider/tasks/gce.yml b/roles/openshift_cloud_provider/tasks/gce.yml index 9e1c31b1d..8b9c1b42a 100644 --- a/roles/openshift_cloud_provider/tasks/gce.yml +++ b/roles/openshift_cloud_provider/tasks/gce.yml @@ -1,11 +1,13 @@ --- - name: check variables are passed fail: - msg: "Ensure correct variables are defined for gcp. {{ item }}" - when: item == '' + msg: "Ensure correct variables are defined for gcp. {{ item.name }}" + when: item.value == '' with_items: - - "{{ openshift_gcp_project }}" - - "{{ openshift_gcp_prefix }}" + - name: openshift_gcp_project + value: "{{ openshift_gcp_project }}" + - name: openshift_gcp_prefix + value: "{{ openshift_gcp_prefix }}" # Work around ini_file create option in 2.2 which defaults to no - name: Create cloud config file @@ -28,4 +30,4 @@ - { key: 'network-name', value: '{{ openshift_gcp_network_name }}' } - { key: 'node-tags', value: '{{ openshift_gcp_prefix }}ocp' } - { key: 'node-instance-prefix', value: '{{ openshift_gcp_prefix }}' } - - { key: 'multizone', value: 'false' } + - { key: 'multizone', value: '{{ openshift_gcp_multizone | string }}' } diff --git a/roles/openshift_etcd_facts/tasks/set_etcd_ca_host.yml b/roles/openshift_etcd_facts/tasks/set_etcd_ca_host.yml index bf8d28a9b..624ad714e 100644 --- a/roles/openshift_etcd_facts/tasks/set_etcd_ca_host.yml +++ b/roles/openshift_etcd_facts/tasks/set_etcd_ca_host.yml @@ -14,10 +14,10 @@ # and /etc/etcd/generated_certs directories. - set_fact: __etcd_ca_dir_hosts: "{{ __etcd_ca_host_stat.results - | lib_utils_oo_collect('_ansible_delegated_vars.ansible_host', + | lib_utils_oo_collect('_ansible_delegated_vars.inventory_hostname', filters={'stat.path':'/etc/etcd/ca','stat.exists':True}) }}" __etcd_generated_certs_dir_hosts: "{{ __etcd_ca_host_stat.results - | lib_utils_oo_collect('_ansible_delegated_vars.ansible_host', + | lib_utils_oo_collect('_ansible_delegated_vars.inventory_hostname', filters={'stat.path':'/etc/etcd/generated_certs','stat.exists':True}) }}" run_once: true diff --git a/roles/openshift_gcp/defaults/main.yml b/roles/openshift_gcp/defaults/main.yml index 18fc453b2..f0cbb2f32 100644 --- a/roles/openshift_gcp/defaults/main.yml +++ b/roles/openshift_gcp/defaults/main.yml @@ -56,3 +56,5 @@ openshift_gcp_node_group_config: openshift_gcp_startup_script_file: '' openshift_gcp_user_data_file: '' + +openshift_gcp_multizone: False diff --git a/roles/openshift_gcp/tasks/node_cloud_config.yml b/roles/openshift_gcp/tasks/node_cloud_config.yml index 4e982f497..c38a052ea 100644 --- a/roles/openshift_gcp/tasks/node_cloud_config.yml +++ b/roles/openshift_gcp/tasks/node_cloud_config.yml @@ -9,4 +9,4 @@ - { key: 'network-name', value: '{{ openshift_gcp_network_name }}' } - { key: 'node-tags', value: '{{ openshift_gcp_prefix }}ocp' } - { key: 'node-instance-prefix', value: '{{ openshift_gcp_prefix }}' } - - { key: 'multizone', value: 'false' } + - { key: 'multizone', value: '{{ openshift_gcp_multizone | string }}' } diff --git a/roles/openshift_logging_eventrouter/templates/2.x/eventrouter-template.j2 b/roles/openshift_logging_eventrouter/templates/2.x/eventrouter-template.j2 new file mode 100644 index 000000000..3bd29163b --- /dev/null +++ b/roles/openshift_logging_eventrouter/templates/2.x/eventrouter-template.j2 @@ -0,0 +1,109 @@ +# this jinja2 template should always match (except nodeSelector) openshift template in +# ../files/eventrouter-template.yaml +kind: Template +apiVersion: v1 +metadata: + name: eventrouter-template + annotations: + description: "A pod forwarding kubernetes events to EFK aggregated logging stack." + tags: "events,EFK,logging" +objects: + - kind: ServiceAccount + apiVersion: v1 + metadata: + name: aggregated-logging-eventrouter + - kind: ClusterRole + apiVersion: v1 + metadata: + name: event-reader + rules: + - apiGroups: [""] + resources: ["events"] + verbs: ["get", "watch", "list"] + - kind: ConfigMap + apiVersion: v1 + metadata: + name: logging-eventrouter + data: + config.json: |- + { + "sink": "${SINK}" + } + - kind: DeploymentConfig + apiVersion: v1 + metadata: + name: logging-eventrouter + labels: + component: eventrouter + logging-infra: eventrouter + provider: openshift + spec: + selector: + component: eventrouter + logging-infra: eventrouter + provider: openshift + replicas: "${{ '{{' }}REPLICAS{{ '}}' }}" + template: + metadata: + labels: + component: eventrouter + logging-infra: eventrouter + provider: openshift + name: logging-eventrouter + spec: + serviceAccount: aggregated-logging-eventrouter + serviceAccountName: aggregated-logging-eventrouter +{% if node_selector is iterable and node_selector | length > 0 %} + nodeSelector: +{% for key, value in node_selector.items() %} + {{ key }}: "{{ value }}" +{% endfor %} +{% endif %} + containers: + - name: kube-eventrouter + image: ${IMAGE} + imagePullPolicy: IfNotPresent + resources: + limits: + memory: ${MEMORY} + requires: + cpu: ${CPU} + memory: ${MEMORY} + volumeMounts: + - name: config-volume + mountPath: /etc/eventrouter + volumes: + - name: config-volume + configMap: + name: logging-eventrouter + - kind: ClusterRoleBinding + apiVersion: v1 + metadata: + name: event-reader-binding + subjects: + - kind: ServiceAccount + name: aggregated-logging-eventrouter + namespace: ${NAMESPACE} + roleRef: + kind: ClusterRole + name: event-reader + +parameters: + - name: SINK + displayName: Sink + value: stdout + - name: REPLICAS + displayName: Replicas + value: "1" + - name: IMAGE + displayName: Image + value: "docker.io/openshift/origin-logging-eventrouter:latest" + - name: MEMORY + displayName: Memory + value: "128Mi" + - name: CPU + displayName: CPU + value: "100m" + - name: NAMESPACE + displayName: Namespace + value: default diff --git a/roles/openshift_node/README.md b/roles/openshift_node/README.md index 87ceb8103..c61742bc2 100644 --- a/roles/openshift_node/README.md +++ b/roles/openshift_node/README.md @@ -15,10 +15,17 @@ Role Variables -------------- From this role: -| Name | Default value | | -|----------------------------|-----------------------|----------------------------------------------------------| -| oreg_url | UNDEF (Optional) | Default docker registry to use | -| oreg_url_node | UNDEF (Optional) | Default docker registry to use, specifically on the node | +| Name | Default value | | +|------------------------------|-----------------------|----------------------------------------------------------| +| openshift_node_start_options | UNDEF (Optional) | Options to pass to node start cmdline | +| oreg_url | UNDEF (Optional) | Default docker registry to use | +| oreg_url_node | UNDEF (Optional) | Default docker registry to use, specifically on the node | + +openshift_node_start_options can be used for passing any start node option, e.g.: + +--enable=kubelet,plugins + +Which would have a node running without kube-proxy and dns. Dependencies ------------ diff --git a/roles/openshift_node/defaults/main.yml b/roles/openshift_node/defaults/main.yml index 64ab07bb5..9f887891b 100644 --- a/roles/openshift_node/defaults/main.yml +++ b/roles/openshift_node/defaults/main.yml @@ -112,7 +112,7 @@ l_is_openvswitch_system_container: "{{ (openshift_use_openvswitch_system_contain openshift_image_tag: '' default_r_openshift_node_image_prep_packages: -#- "{{ openshift_service_type }}-master" +- "{{ openshift_service_type }}-master" - "{{ openshift_service_type }}-node" - "{{ openshift_service_type }}-docker-excluder" - "{{ openshift_service_type }}-sdn-ovs" diff --git a/roles/openshift_node/tasks/bootstrap.yml b/roles/openshift_node/tasks/bootstrap.yml index f9f042eeb..4abd060c4 100644 --- a/roles/openshift_node/tasks/bootstrap.yml +++ b/roles/openshift_node/tasks/bootstrap.yml @@ -1,11 +1,7 @@ --- -- name: install needed rpm(s) - package: - name: "{{ item }}" - state: present - with_items: "{{ r_openshift_node_image_prep_packages }}" - register: result - until: result is succeeded +- name: include package installs + import_tasks: install_rpms.yml + when: not (openshift_is_atomic | default(False) | bool) - name: create the directory for node file: diff --git a/roles/openshift_node/tasks/config/configure-node-settings.yml b/roles/openshift_node/tasks/config/configure-node-settings.yml index ebc1426d3..dcdbeb220 100644 --- a/roles/openshift_node/tasks/config/configure-node-settings.yml +++ b/roles/openshift_node/tasks/config/configure-node-settings.yml @@ -7,7 +7,7 @@ create: true with_items: - regex: '^OPTIONS=' - line: "OPTIONS=--loglevel={{ openshift_node_debug_level }}" + line: "OPTIONS=--loglevel={{ openshift_node_debug_level }} {{ openshift_node_start_options | default('') }}" - regex: '^CONFIG_FILE=' line: "CONFIG_FILE={{ openshift.common.config_base }}/node/node-config.yaml" - regex: '^IMAGE_VERSION=' diff --git a/roles/openshift_node/tasks/install_rpms.yml b/roles/openshift_node/tasks/install_rpms.yml new file mode 100644 index 000000000..c96e9cdaf --- /dev/null +++ b/roles/openshift_node/tasks/install_rpms.yml @@ -0,0 +1,9 @@ +--- +- name: install needed rpm(s) + package: + name: "{{ item }}" + state: present + with_items: "{{ r_openshift_node_image_prep_packages }}" + register: result + until: result is succeeded + when: not (openshift_is_atomic | default(False) | bool) diff --git a/roles/openshift_openstack/defaults/main.yml b/roles/openshift_openstack/defaults/main.yml index 75f1300e1..6c7e5b543 100644 --- a/roles/openshift_openstack/defaults/main.yml +++ b/roles/openshift_openstack/defaults/main.yml @@ -21,16 +21,15 @@ openshift_openstack_cluster_node_labels: openshift_openstack_install_debug_packages: false openshift_openstack_required_packages: - - docker - NetworkManager - - wget - - git - - net-tools - - bind-utils - - bridge-utils openshift_openstack_debug_packages: - bash-completion + - bind-utils + - bridge-utils + - git + - net-tools - vim-enhanced + - wget # container-storage-setup openshift_openstack_container_storage_setup: diff --git a/roles/openshift_persistent_volumes/templates/persistent-volume-claim.yml.j2 b/roles/openshift_persistent_volumes/templates/persistent-volume-claim.yml.j2 index fac589a92..ca8b747ee 100644 --- a/roles/openshift_persistent_volumes/templates/persistent-volume-claim.yml.j2 +++ b/roles/openshift_persistent_volumes/templates/persistent-volume-claim.yml.j2 @@ -12,4 +12,7 @@ items: resources: requests: storage: "{{ claim.capacity }}" +{% if claim.storageclass is not None %} + storageClassName: "{{ claim.storageclass }}" +{% endif %} {% endfor %} diff --git a/roles/openshift_storage_glusterfs/tasks/glusterfs_config.yml b/roles/openshift_storage_glusterfs/tasks/glusterfs_config.yml index 92de1b64d..b50050956 100644 --- a/roles/openshift_storage_glusterfs/tasks/glusterfs_config.yml +++ b/roles/openshift_storage_glusterfs/tasks/glusterfs_config.yml @@ -1,53 +1,3 @@ --- -- set_fact: - glusterfs_timeout: "{{ openshift_storage_glusterfs_timeout }}" - glusterfs_namespace: "{{ openshift_storage_glusterfs_namespace }}" - glusterfs_is_native: "{{ openshift_storage_glusterfs_is_native | bool }}" - glusterfs_name: "{{ openshift_storage_glusterfs_name }}" - # map_from_pairs is a custom filter plugin in role lib_utils - glusterfs_nodeselector: "{{ openshift_storage_glusterfs_nodeselector | default(['storagenode', openshift_storage_glusterfs_name] | join('=')) | map_from_pairs }}" - glusterfs_use_default_selector: "{{ openshift_storage_glusterfs_use_default_selector }}" - glusterfs_storageclass: "{{ openshift_storage_glusterfs_storageclass }}" - glusterfs_storageclass_default: "{{ openshift_storage_glusterfs_storageclass_default | bool }}" - glusterfs_image: "{{ openshift_storage_glusterfs_image }}" - glusterfs_version: "{{ openshift_storage_glusterfs_version }}" - glusterfs_block_deploy: "{{ openshift_storage_glusterfs_block_deploy | bool }}" - glusterfs_block_image: "{{ openshift_storage_glusterfs_block_image }}" - glusterfs_block_version: "{{ openshift_storage_glusterfs_block_version }}" - glusterfs_block_host_vol_create: "{{ openshift_storage_glusterfs_block_host_vol_create }}" - glusterfs_block_host_vol_size: "{{ openshift_storage_glusterfs_block_host_vol_size }}" - glusterfs_block_host_vol_max: "{{ openshift_storage_glusterfs_block_host_vol_max }}" - glusterfs_block_storageclass: "{{ openshift_storage_glusterfs_block_storageclass | bool }}" - glusterfs_block_storageclass_default: "{{ openshift_storage_glusterfs_block_storageclass_default | bool }}" - glusterfs_s3_deploy: "{{ openshift_storage_glusterfs_s3_deploy | bool }}" - glusterfs_s3_image: "{{ openshift_storage_glusterfs_s3_image }}" - glusterfs_s3_version: "{{ openshift_storage_glusterfs_s3_version }}" - glusterfs_s3_account: "{{ openshift_storage_glusterfs_s3_account }}" - glusterfs_s3_user: "{{ openshift_storage_glusterfs_s3_user }}" - glusterfs_s3_password: "{{ openshift_storage_glusterfs_s3_password }}" - glusterfs_s3_pvc: "{{ openshift_storage_glusterfs_s3_pvc }}" - glusterfs_s3_pvc_size: "{{ openshift_storage_glusterfs_s3_pvc_size }}" - glusterfs_s3_meta_pvc: "{{ openshift_storage_glusterfs_s3_meta_pvc }}" - glusterfs_s3_meta_pvc_size: "{{ openshift_storage_glusterfs_s3_meta_pvc_size }}" - glusterfs_wipe: "{{ openshift_storage_glusterfs_wipe | bool }}" - glusterfs_heketi_is_native: "{{ openshift_storage_glusterfs_heketi_is_native | bool }}" - glusterfs_heketi_is_missing: "{{ openshift_storage_glusterfs_heketi_is_missing | bool }}" - glusterfs_heketi_deploy_is_missing: "{{ openshift_storage_glusterfs_heketi_deploy_is_missing | bool }}" - glusterfs_heketi_cli: "{{ openshift_storage_glusterfs_heketi_cli }}" - glusterfs_heketi_image: "{{ openshift_storage_glusterfs_heketi_image }}" - glusterfs_heketi_version: "{{ openshift_storage_glusterfs_heketi_version }}" - glusterfs_heketi_admin_key: "{{ openshift_storage_glusterfs_heketi_admin_key }}" - glusterfs_heketi_user_key: "{{ openshift_storage_glusterfs_heketi_user_key }}" - glusterfs_heketi_topology_load: "{{ openshift_storage_glusterfs_heketi_topology_load | bool }}" - glusterfs_heketi_wipe: "{{ openshift_storage_glusterfs_heketi_wipe | bool }}" - glusterfs_heketi_url: "{{ openshift_storage_glusterfs_heketi_url }}" - glusterfs_heketi_port: "{{ openshift_storage_glusterfs_heketi_port }}" - glusterfs_heketi_executor: "{{ openshift_storage_glusterfs_heketi_executor }}" - glusterfs_heketi_ssh_port: "{{ openshift_storage_glusterfs_heketi_ssh_port }}" - glusterfs_heketi_ssh_user: "{{ openshift_storage_glusterfs_heketi_ssh_user }}" - glusterfs_heketi_ssh_sudo: "{{ openshift_storage_glusterfs_heketi_ssh_sudo | bool }}" - glusterfs_heketi_ssh_keyfile: "{{ openshift_storage_glusterfs_heketi_ssh_keyfile }}" - glusterfs_heketi_fstab: "{{ openshift_storage_glusterfs_heketi_fstab }}" - glusterfs_nodes: "{{ groups.glusterfs | default([]) }}" - +- include_tasks: glusterfs_config_facts.yml - include_tasks: glusterfs_common.yml diff --git a/roles/openshift_storage_glusterfs/tasks/glusterfs_config_facts.yml b/roles/openshift_storage_glusterfs/tasks/glusterfs_config_facts.yml new file mode 100644 index 000000000..67d30bf25 --- /dev/null +++ b/roles/openshift_storage_glusterfs/tasks/glusterfs_config_facts.yml @@ -0,0 +1,51 @@ +--- +- set_fact: + glusterfs_timeout: "{{ openshift_storage_glusterfs_timeout }}" + glusterfs_namespace: "{{ openshift_storage_glusterfs_namespace }}" + glusterfs_is_native: "{{ openshift_storage_glusterfs_is_native | bool }}" + glusterfs_name: "{{ openshift_storage_glusterfs_name }}" + # map_from_pairs is a custom filter plugin in role lib_utils + glusterfs_nodeselector: "{{ openshift_storage_glusterfs_nodeselector | default(['storagenode', openshift_storage_glusterfs_name] | join('=')) | map_from_pairs }}" + glusterfs_use_default_selector: "{{ openshift_storage_glusterfs_use_default_selector }}" + glusterfs_storageclass: "{{ openshift_storage_glusterfs_storageclass }}" + glusterfs_storageclass_default: "{{ openshift_storage_glusterfs_storageclass_default | bool }}" + glusterfs_image: "{{ openshift_storage_glusterfs_image }}" + glusterfs_version: "{{ openshift_storage_glusterfs_version }}" + glusterfs_block_deploy: "{{ openshift_storage_glusterfs_block_deploy | bool }}" + glusterfs_block_image: "{{ openshift_storage_glusterfs_block_image }}" + glusterfs_block_version: "{{ openshift_storage_glusterfs_block_version }}" + glusterfs_block_host_vol_create: "{{ openshift_storage_glusterfs_block_host_vol_create }}" + glusterfs_block_host_vol_size: "{{ openshift_storage_glusterfs_block_host_vol_size }}" + glusterfs_block_host_vol_max: "{{ openshift_storage_glusterfs_block_host_vol_max }}" + glusterfs_block_storageclass: "{{ openshift_storage_glusterfs_block_storageclass | bool }}" + glusterfs_block_storageclass_default: "{{ openshift_storage_glusterfs_block_storageclass_default | bool }}" + glusterfs_s3_deploy: "{{ openshift_storage_glusterfs_s3_deploy | bool }}" + glusterfs_s3_image: "{{ openshift_storage_glusterfs_s3_image }}" + glusterfs_s3_version: "{{ openshift_storage_glusterfs_s3_version }}" + glusterfs_s3_account: "{{ openshift_storage_glusterfs_s3_account }}" + glusterfs_s3_user: "{{ openshift_storage_glusterfs_s3_user }}" + glusterfs_s3_password: "{{ openshift_storage_glusterfs_s3_password }}" + glusterfs_s3_pvc: "{{ openshift_storage_glusterfs_s3_pvc }}" + glusterfs_s3_pvc_size: "{{ openshift_storage_glusterfs_s3_pvc_size }}" + glusterfs_s3_meta_pvc: "{{ openshift_storage_glusterfs_s3_meta_pvc }}" + glusterfs_s3_meta_pvc_size: "{{ openshift_storage_glusterfs_s3_meta_pvc_size }}" + glusterfs_wipe: "{{ openshift_storage_glusterfs_wipe | bool }}" + glusterfs_heketi_is_native: "{{ openshift_storage_glusterfs_heketi_is_native | bool }}" + glusterfs_heketi_is_missing: "{{ openshift_storage_glusterfs_heketi_is_missing | bool }}" + glusterfs_heketi_deploy_is_missing: "{{ openshift_storage_glusterfs_heketi_deploy_is_missing | bool }}" + glusterfs_heketi_cli: "{{ openshift_storage_glusterfs_heketi_cli }}" + glusterfs_heketi_image: "{{ openshift_storage_glusterfs_heketi_image }}" + glusterfs_heketi_version: "{{ openshift_storage_glusterfs_heketi_version }}" + glusterfs_heketi_admin_key: "{{ openshift_storage_glusterfs_heketi_admin_key }}" + glusterfs_heketi_user_key: "{{ openshift_storage_glusterfs_heketi_user_key }}" + glusterfs_heketi_topology_load: "{{ openshift_storage_glusterfs_heketi_topology_load | bool }}" + glusterfs_heketi_wipe: "{{ openshift_storage_glusterfs_heketi_wipe | bool }}" + glusterfs_heketi_url: "{{ openshift_storage_glusterfs_heketi_url }}" + glusterfs_heketi_port: "{{ openshift_storage_glusterfs_heketi_port }}" + glusterfs_heketi_executor: "{{ openshift_storage_glusterfs_heketi_executor }}" + glusterfs_heketi_ssh_port: "{{ openshift_storage_glusterfs_heketi_ssh_port }}" + glusterfs_heketi_ssh_user: "{{ openshift_storage_glusterfs_heketi_ssh_user }}" + glusterfs_heketi_ssh_sudo: "{{ openshift_storage_glusterfs_heketi_ssh_sudo | bool }}" + glusterfs_heketi_ssh_keyfile: "{{ openshift_storage_glusterfs_heketi_ssh_keyfile }}" + glusterfs_heketi_fstab: "{{ openshift_storage_glusterfs_heketi_fstab }}" + glusterfs_nodes: "{{ groups.glusterfs | default([]) }}" diff --git a/roles/openshift_storage_glusterfs/tasks/glusterfs_registry.yml b/roles/openshift_storage_glusterfs/tasks/glusterfs_registry.yml index 10c29fd37..e91e13033 100644 --- a/roles/openshift_storage_glusterfs/tasks/glusterfs_registry.yml +++ b/roles/openshift_storage_glusterfs/tasks/glusterfs_registry.yml @@ -1,54 +1,5 @@ --- -- set_fact: - glusterfs_timeout: "{{ openshift_storage_glusterfs_registry_timeout }}" - glusterfs_namespace: "{{ openshift_storage_glusterfs_registry_namespace }}" - glusterfs_is_native: "{{ openshift_storage_glusterfs_registry_is_native | bool }}" - glusterfs_name: "{{ openshift_storage_glusterfs_registry_name }}" - # map_from_pairs is a custom filter plugin in role lib_utils - glusterfs_nodeselector: "{{ openshift_storage_glusterfs_registry_nodeselector | default(['storagenode', openshift_storage_glusterfs_registry_name] | join('=')) | map_from_pairs }}" - glusterfs_use_default_selector: "{{ openshift_storage_glusterfs_registry_use_default_selector }}" - glusterfs_storageclass: "{{ openshift_storage_glusterfs_registry_storageclass }}" - glusterfs_storageclass_default: "{{ openshift_storage_glusterfs_registry_storageclass_default | bool }}" - glusterfs_image: "{{ openshift_storage_glusterfs_registry_image }}" - glusterfs_version: "{{ openshift_storage_glusterfs_registry_version }}" - glusterfs_block_deploy: "{{ openshift_storage_glusterfs_registry_block_deploy | bool }}" - glusterfs_block_image: "{{ openshift_storage_glusterfs_registry_block_image }}" - glusterfs_block_version: "{{ openshift_storage_glusterfs_registry_block_version }}" - glusterfs_block_host_vol_create: "{{ openshift_storage_glusterfs_registry_block_host_vol_create }}" - glusterfs_block_host_vol_size: "{{ openshift_storage_glusterfs_registry_block_host_vol_size }}" - glusterfs_block_host_vol_max: "{{ openshift_storage_glusterfs_registry_block_host_vol_max }}" - glusterfs_block_storageclass: "{{ openshift_storage_glusterfs_registry_block_storageclass | bool }}" - glusterfs_block_storageclass_default: "{{ openshift_storage_glusterfs_registry_block_storageclass_default | bool }}" - glusterfs_s3_deploy: "{{ openshift_storage_glusterfs_registry_s3_deploy | bool }}" - glusterfs_s3_image: "{{ openshift_storage_glusterfs_registry_s3_image }}" - glusterfs_s3_version: "{{ openshift_storage_glusterfs_registry_s3_version }}" - glusterfs_s3_account: "{{ openshift_storage_glusterfs_registry_s3_account }}" - glusterfs_s3_user: "{{ openshift_storage_glusterfs_registry_s3_user }}" - glusterfs_s3_password: "{{ openshift_storage_glusterfs_registry_s3_password }}" - glusterfs_s3_pvc: "{{ openshift_storage_glusterfs_registry_s3_pvc }}" - glusterfs_s3_pvc_size: "{{ openshift_storage_glusterfs_registry_s3_pvc_size }}" - glusterfs_s3_meta_pvc: "{{ openshift_storage_glusterfs_registry_s3_meta_pvc }}" - glusterfs_s3_meta_pvc_size: "{{ openshift_storage_glusterfs_registry_s3_meta_pvc_size }}" - glusterfs_wipe: "{{ openshift_storage_glusterfs_registry_wipe | bool }}" - glusterfs_heketi_is_native: "{{ openshift_storage_glusterfs_registry_heketi_is_native | bool }}" - glusterfs_heketi_is_missing: "{{ openshift_storage_glusterfs_registry_heketi_is_missing | bool }}" - glusterfs_heketi_deploy_is_missing: "{{ openshift_storage_glusterfs_registry_heketi_deploy_is_missing | bool }}" - glusterfs_heketi_cli: "{{ openshift_storage_glusterfs_registry_heketi_cli }}" - glusterfs_heketi_image: "{{ openshift_storage_glusterfs_registry_heketi_image }}" - glusterfs_heketi_version: "{{ openshift_storage_glusterfs_registry_heketi_version }}" - glusterfs_heketi_admin_key: "{{ openshift_storage_glusterfs_registry_heketi_admin_key }}" - glusterfs_heketi_user_key: "{{ openshift_storage_glusterfs_registry_heketi_user_key }}" - glusterfs_heketi_topology_load: "{{ openshift_storage_glusterfs_registry_heketi_topology_load | bool }}" - glusterfs_heketi_wipe: "{{ openshift_storage_glusterfs_registry_heketi_wipe | bool }}" - glusterfs_heketi_url: "{{ openshift_storage_glusterfs_registry_heketi_url }}" - glusterfs_heketi_port: "{{ openshift_storage_glusterfs_registry_heketi_port }}" - glusterfs_heketi_executor: "{{ openshift_storage_glusterfs_registry_heketi_executor }}" - glusterfs_heketi_ssh_port: "{{ openshift_storage_glusterfs_registry_heketi_ssh_port }}" - glusterfs_heketi_ssh_user: "{{ openshift_storage_glusterfs_registry_heketi_ssh_user }}" - glusterfs_heketi_ssh_sudo: "{{ openshift_storage_glusterfs_registry_heketi_ssh_sudo | bool }}" - glusterfs_heketi_ssh_keyfile: "{{ openshift_storage_glusterfs_registry_heketi_ssh_keyfile }}" - glusterfs_heketi_fstab: "{{ openshift_storage_glusterfs_registry_heketi_fstab }}" - glusterfs_nodes: "{% if groups.glusterfs_registry is defined and groups['glusterfs_registry'] | length > 0 %}{% set nodes = groups.glusterfs_registry %}{% elif 'groups.glusterfs' is defined and groups['glusterfs'] | length > 0 %}{% set nodes = groups.glusterfs %}{% else %}{% set nodes = '[]' %}{% endif %}{{ nodes }}" +- include_tasks: glusterfs_registry_facts.yml - include_tasks: glusterfs_common.yml when: diff --git a/roles/openshift_storage_glusterfs/tasks/glusterfs_registry_facts.yml b/roles/openshift_storage_glusterfs/tasks/glusterfs_registry_facts.yml new file mode 100644 index 000000000..5fa5f0895 --- /dev/null +++ b/roles/openshift_storage_glusterfs/tasks/glusterfs_registry_facts.yml @@ -0,0 +1,51 @@ +--- +- set_fact: + glusterfs_timeout: "{{ openshift_storage_glusterfs_registry_timeout }}" + glusterfs_namespace: "{{ openshift_storage_glusterfs_registry_namespace }}" + glusterfs_is_native: "{{ openshift_storage_glusterfs_registry_is_native | bool }}" + glusterfs_name: "{{ openshift_storage_glusterfs_registry_name }}" + # map_from_pairs is a custom filter plugin in role lib_utils + glusterfs_nodeselector: "{{ openshift_storage_glusterfs_registry_nodeselector | default(['storagenode', openshift_storage_glusterfs_registry_name] | join('=')) | map_from_pairs }}" + glusterfs_use_default_selector: "{{ openshift_storage_glusterfs_registry_use_default_selector }}" + glusterfs_storageclass: "{{ openshift_storage_glusterfs_registry_storageclass }}" + glusterfs_storageclass_default: "{{ openshift_storage_glusterfs_registry_storageclass_default | bool }}" + glusterfs_image: "{{ openshift_storage_glusterfs_registry_image }}" + glusterfs_version: "{{ openshift_storage_glusterfs_registry_version }}" + glusterfs_block_deploy: "{{ openshift_storage_glusterfs_registry_block_deploy | bool }}" + glusterfs_block_image: "{{ openshift_storage_glusterfs_registry_block_image }}" + glusterfs_block_version: "{{ openshift_storage_glusterfs_registry_block_version }}" + glusterfs_block_host_vol_create: "{{ openshift_storage_glusterfs_registry_block_host_vol_create }}" + glusterfs_block_host_vol_size: "{{ openshift_storage_glusterfs_registry_block_host_vol_size }}" + glusterfs_block_host_vol_max: "{{ openshift_storage_glusterfs_registry_block_host_vol_max }}" + glusterfs_block_storageclass: "{{ openshift_storage_glusterfs_registry_block_storageclass | bool }}" + glusterfs_block_storageclass_default: "{{ openshift_storage_glusterfs_registry_block_storageclass_default | bool }}" + glusterfs_s3_deploy: "{{ openshift_storage_glusterfs_registry_s3_deploy | bool }}" + glusterfs_s3_image: "{{ openshift_storage_glusterfs_registry_s3_image }}" + glusterfs_s3_version: "{{ openshift_storage_glusterfs_registry_s3_version }}" + glusterfs_s3_account: "{{ openshift_storage_glusterfs_registry_s3_account }}" + glusterfs_s3_user: "{{ openshift_storage_glusterfs_registry_s3_user }}" + glusterfs_s3_password: "{{ openshift_storage_glusterfs_registry_s3_password }}" + glusterfs_s3_pvc: "{{ openshift_storage_glusterfs_registry_s3_pvc }}" + glusterfs_s3_pvc_size: "{{ openshift_storage_glusterfs_registry_s3_pvc_size }}" + glusterfs_s3_meta_pvc: "{{ openshift_storage_glusterfs_registry_s3_meta_pvc }}" + glusterfs_s3_meta_pvc_size: "{{ openshift_storage_glusterfs_registry_s3_meta_pvc_size }}" + glusterfs_wipe: "{{ openshift_storage_glusterfs_registry_wipe | bool }}" + glusterfs_heketi_is_native: "{{ openshift_storage_glusterfs_registry_heketi_is_native | bool }}" + glusterfs_heketi_is_missing: "{{ openshift_storage_glusterfs_registry_heketi_is_missing | bool }}" + glusterfs_heketi_deploy_is_missing: "{{ openshift_storage_glusterfs_registry_heketi_deploy_is_missing | bool }}" + glusterfs_heketi_cli: "{{ openshift_storage_glusterfs_registry_heketi_cli }}" + glusterfs_heketi_image: "{{ openshift_storage_glusterfs_registry_heketi_image }}" + glusterfs_heketi_version: "{{ openshift_storage_glusterfs_registry_heketi_version }}" + glusterfs_heketi_admin_key: "{{ openshift_storage_glusterfs_registry_heketi_admin_key }}" + glusterfs_heketi_user_key: "{{ openshift_storage_glusterfs_registry_heketi_user_key }}" + glusterfs_heketi_topology_load: "{{ openshift_storage_glusterfs_registry_heketi_topology_load | bool }}" + glusterfs_heketi_wipe: "{{ openshift_storage_glusterfs_registry_heketi_wipe | bool }}" + glusterfs_heketi_url: "{{ openshift_storage_glusterfs_registry_heketi_url }}" + glusterfs_heketi_port: "{{ openshift_storage_glusterfs_registry_heketi_port }}" + glusterfs_heketi_executor: "{{ openshift_storage_glusterfs_registry_heketi_executor }}" + glusterfs_heketi_ssh_port: "{{ openshift_storage_glusterfs_registry_heketi_ssh_port }}" + glusterfs_heketi_ssh_user: "{{ openshift_storage_glusterfs_registry_heketi_ssh_user }}" + glusterfs_heketi_ssh_sudo: "{{ openshift_storage_glusterfs_registry_heketi_ssh_sudo | bool }}" + glusterfs_heketi_ssh_keyfile: "{{ openshift_storage_glusterfs_registry_heketi_ssh_keyfile }}" + glusterfs_heketi_fstab: "{{ openshift_storage_glusterfs_registry_heketi_fstab }}" + glusterfs_nodes: "{% if groups.glusterfs_registry is defined and groups['glusterfs_registry'] | length > 0 %}{% set nodes = groups.glusterfs_registry %}{% elif 'groups.glusterfs' is defined and groups['glusterfs'] | length > 0 %}{% set nodes = groups.glusterfs %}{% else %}{% set nodes = '[]' %}{% endif %}{{ nodes }}" diff --git a/roles/openshift_storage_glusterfs/tasks/glusterfs_uninstall.yml b/roles/openshift_storage_glusterfs/tasks/glusterfs_uninstall.yml new file mode 100644 index 000000000..a5774cc75 --- /dev/null +++ b/roles/openshift_storage_glusterfs/tasks/glusterfs_uninstall.yml @@ -0,0 +1,116 @@ +--- + +- name: Delete pre-existing heketi resources + oc_obj: + namespace: "{{ glusterfs_namespace }}" + kind: "{{ item.kind }}" + name: "{{ item.name | default(omit) }}" + selector: "{{ item.selector | default(omit) }}" + state: absent + with_items: + - kind: "template,route,service,dc,jobs,secret" + selector: "deploy-heketi" + - kind: "svc" + name: "heketi-storage-endpoints" + - kind: "svc" + name: "heketi-storage" + - kind: "secret" + name: "heketi-{{ glusterfs_name }}-topology-secret" + - kind: "template,route,service,dc" + name: "heketi-{{ glusterfs_name }}" + - kind: "svc" + name: "heketi-db-{{ glusterfs_name }}-endpoints" + - kind: "sa" + name: "heketi-{{ glusterfs_name }}-service-account" + - kind: "secret" + name: "heketi-{{ glusterfs_name }}-admin-secret" + - kind: "secret" + name: "heketi-{{ glusterfs_name }}-config-secret" + failed_when: False + +- name: Delete pre-existing GlusterFS resources + oc_obj: + namespace: "{{ glusterfs_namespace }}" + kind: "{{ item.kind }}" + name: "{{ item.name }}" + state: absent + with_items: + - kind: template + name: glusterfs + - kind: daemonset + name: "glusterfs-{{ glusterfs_name }}" + - kind: storageclass + name: "glusterfs-{{ glusterfs_name }}" + +- name: Unlabel any existing GlusterFS nodes + oc_label: + name: "{{ hostvars[item].openshift.node.nodename }}" + kind: node + state: absent + labels: "{{ glusterfs_nodeselector | lib_utils_oo_dict_to_list_of_dict }}" + with_items: "{{ groups.all }}" + +- name: Delete pre-existing GlusterFS config + file: + path: /var/lib/glusterd + state: absent + delegate_to: "{{ item }}" + with_items: "{{ glusterfs_nodes | default([]) }}" + +- name: Delete pre-existing additional GlusterFS config + file: + path: /etc/glusterfs + state: absent + delegate_to: "{{ item }}" + with_items: "{{ glusterfs_nodes | default([]) }}" + +- name: Delete pre-existing Heketi config + file: + path: /var/lib/heketi + state: absent + delegate_to: "{{ item }}" + with_items: "{{ glusterfs_nodes | default([]) }}" + +- name: Delete Glusterfs logs + file: + path: /var/log/glusterfs + state: absent + delegate_to: "{{ item }}" + with_items: "{{ glusterfs_nodes | default([]) }}" + +- name: Delete deploy resources + oc_obj: + namespace: "{{ glusterfs_namespace }}" + kind: "{{ item.kind }}" + name: "{{ item.name | default(omit) }}" + selector: "{{ item.selector | default(omit) }}" + state: absent + with_items: + - kind: "template,route,service,jobs,dc,secret" + selector: "deploy-heketi" + - kind: "svc" + name: "heketi-storage-endpoints" + - kind: "secret" + name: "heketi-{{ glusterfs_name }}-topology-secret" + +- name: Get GlusterFS storage devices state + command: "pvdisplay -C --noheadings -o pv_name,vg_name {% for device in hostvars[item].glusterfs_devices %}{{ device }} {% endfor %}" + register: devices_info + delegate_to: "{{ item }}" + with_items: "{{ glusterfs_nodes | default([]) }}" + failed_when: False + when: glusterfs_wipe + + # Runs "lvremove -ff <vg>; vgremove -fy <vg>; pvremove -fy <pv>" for every device found to be a physical volume. +- name: Clear GlusterFS storage device contents + shell: "{% for line in item.stdout_lines %}{% set fields = line.split() %}{% if fields | count > 1 %}lvremove -ff {{ fields[1] }}; vgremove -fy {{ fields[1] }}; {% endif %}pvremove -fy {{ fields[0] }}; {% endfor %}" + delegate_to: "{{ item.item }}" + with_items: "{{ devices_info.results }}" + register: clear_devices + until: + - "'contains a filesystem in use' not in clear_devices.stderr" + delay: 1 + retries: 30 + when: + - glusterfs_wipe + - item.stdout_lines | count > 0 diff --git a/roles/openshift_storage_glusterfs/tasks/uninstall.yml b/roles/openshift_storage_glusterfs/tasks/uninstall.yml new file mode 100644 index 000000000..dcf0c9357 --- /dev/null +++ b/roles/openshift_storage_glusterfs/tasks/uninstall.yml @@ -0,0 +1,12 @@ +--- +- name: uninstall glusterfs + block: + - include_tasks: glusterfs_config_facts.yml + - include_tasks: glusterfs_uninstall.yml + when: "'glusterfs' in groups and groups['glusterfs'] | length > 0" + +- name: uninstall glusterfs registry + block: + - include_tasks: glusterfs_registry_facts.yml + - include_tasks: glusterfs_uninstall.yml + when: "'glusterfs_registry' in groups and groups['glusterfs_registry'] | length > 0" |