diff --git a/plugins/module_utils/base.py b/plugins/module_utils/base.py index 0b810ca..e3e3a6f 100644 --- a/plugins/module_utils/base.py +++ b/plugins/module_utils/base.py @@ -138,7 +138,7 @@ def __init__(self, params, module=None): self.params['token'] = f.read().strip() def _open_url(self, path, method, data=None, fatal=True): - url = '{0}/v1/{1}'.format(self.params['vault_addr'], path) + url = f'{self.params["vault_addr"]}/v1/{path}' headers = {} if self.params.get('token'): @@ -178,7 +178,7 @@ def _open_url(self, path, method, data=None, fatal=True): except HTTPError as e: if fatal and self._module: - msg = 'Failed to {0} {1}: {2} (HTTP {3})'.format(method, path, e.reason, e.code) + msg = f'Failed to {method} {path}: {e.reason} (HTTP {e.code})' result = {} try: result = json.loads(e.read()) @@ -194,7 +194,7 @@ def _open_url(self, path, method, data=None, fatal=True): except URLError as e: if fatal and self._module: - self._module.fail_json(msg='Failed to {0} {1}: {2}'.format(method, path, e.reason)) + self._module.fail_json(msg=f'Failed to {method} {path}: {e.reason}') raise def get(self, path, fatal=True): @@ -216,6 +216,6 @@ def delete(self, path, fatal=True): if getattr(e, 'code', 0) == 404: return False if fatal and self._module: - self._module.fail_json(msg='Failed to DELETE {0}: {1}'.format(path, e.reason)) + self._module.fail_json(msg=f'Failed to DELETE {path}: {e.reason}') raise return True diff --git a/plugins/module_utils/mount.py b/plugins/module_utils/mount.py index fc67314..daf8462 100644 --- a/plugins/module_utils/mount.py +++ b/plugins/module_utils/mount.py @@ -72,7 +72,7 @@ def run(self): self.module.exit_json(changed=False) if not self.module.check_mode: - self.client.delete('{0}/{1}'.format(self.base_path, path)) + self.client.delete(f'{self.base_path}/{path}') self.module.exit_json(changed=True, mount=mount) changed = False @@ -96,7 +96,7 @@ def run(self): for key, val in self.params['options'].items(): payload['options'][key] = str(val) - mount_path = '{0}/{1}'.format(self.base_path, path) + mount_path = f'{self.base_path}/{path}' if not mount: changed = True if not self.module.check_mode: @@ -110,7 +110,7 @@ def run(self): if not self.module.check_mode: if mount['type'] != payload['type']: if not self.params['force']: - self.module.fail_json('Existing mount at {0} is {1} and force is false'.format(mount_path, mount['type'])) + self.module.fail_json(f'Existing mount at {mount_path} is {mount["type"]} and force is false') self.client.delete(mount_path) self.client.post(mount_path, data=payload) else: @@ -123,7 +123,7 @@ def run(self): if key not in payload: payload[key] = None - self.client.post('{0}/{1}/tune'.format(self.base_path, path), data=payload) + self.client.post(f'{self.base_path}/{path}/tune', data=payload) mount = self._get_mount(path) self.module.exit_json(changed=changed, mount=mount, diff=diff)