def needs_update(self, files=None, content=None, content_type='yaml'): ''' check to see if we need to update ''' objects = self.get() if objects['returncode'] != 0: return objects data = None if files: data = Utils.get_resource_file(files[0], content_type) elif content and 'data' in content: data = content['data'] else: data = content # if equal then no need. So not equal is True return not Utils.check_def_equal( data, objects['results'][0], skip_keys=None, debug=False)
def needs_update(self): ''' verify an update is needed ''' skip = [] return not Utils.check_def_equal(self.config.data, self.route.yaml_dict, skip_keys=skip, debug=self.verbose)
def run_ansible(params, check_mode): '''run the oc_secret module''' ocsecret = OCSecret(params['namespace'], params['name'], params['type'], params['decode'], oc_binary=params['oc_binary'], verbose=params['debug']) state = params['state'] api_rval = ocsecret.get() ##### # Get ##### if state == 'list': return { 'changed': False, 'ansible_module_results': api_rval, state: 'list' } if not params['name']: return { 'failed': True, 'msg': 'Please specify a name when state is absent|present.' } ######## # Delete ######## if state == 'absent': if not Utils.exists(api_rval['results'], params['name']): return {'changed': False, 'state': 'absent'} if check_mode: return { 'changed': True, 'msg': 'Would have performed a delete.' } api_rval = ocsecret.delete() return { 'changed': True, 'ansible_module_results': api_rval, 'state': 'absent' } if state == 'present': if params['files']: files = params['files'] elif params['contents']: files = Utils.create_tmp_files_from_contents( params['contents']) else: files = [{'name': 'null', 'path': os.devnull}] ######## # Create ######## if not Utils.exists(api_rval['results'], params['name']): if check_mode: return { 'changed': True, 'msg': 'Would have performed a create.' } api_rval = ocsecret.create(files, params['contents'], params['from_literal'], params['cert'], params['key'], force=params['force']) # Remove files if files and params['delete_after']: Utils.cleanup([ftmp['path'] for ftmp in files]) if api_rval['returncode'] != 0: return {'failed': True, 'msg': api_rval} return { 'changed': True, 'ansible_module_results': api_rval, 'state': 'present' } ######## # Update ######## # if update is set to false, return update = params['update'] if not update: return { 'changed': False, 'ansible_module_results': api_rval, 'state': state } secret = ocsecret.prep_secret(params['files'], params['contents'], force=params['force']) if secret['returncode'] != 0: return {'failed': True, 'msg': secret} if Utils.check_def_equal(secret['results'], api_rval['results'][0]): # Remove files if files and params['delete_after']: Utils.cleanup([ftmp['path'] for ftmp in files]) return { 'changed': False, 'ansible_module_results': secret['results'], 'state': 'present' } if check_mode: return { 'changed': True, 'msg': 'Would have performed an update.' } api_rval = ocsecret.update(files, force=params['force']) # Remove files if secret and params['delete_after']: Utils.cleanup([ftmp['path'] for ftmp in files]) if api_rval['returncode'] != 0: return {'failed': True, 'msg': api_rval} return { 'changed': True, 'ansible_module_results': api_rval, 'state': 'present' } return { 'failed': True, 'changed': False, 'msg': 'Unknown state passed. %s' % state, 'state': 'unknown' }
def needs_update(self): '''compare the current configmap with the proposed and return if they are equal''' return not Utils.check_def_equal(self.inc_configmap, self.configmap, debug=self.verbose)