diff --git a/plugins/modules/ec2_metadata_facts.py b/plugins/modules/ec2_metadata_facts.py index 26ecaad0adb..6bc0d529d96 100644 --- a/plugins/modules/ec2_metadata_facts.py +++ b/plugins/modules/ec2_metadata_facts.py @@ -524,17 +524,15 @@ def _fetch(self, url): response, info = fetch_url(self.module, encoded_url, headers=headers, force=True) if info.get("status") in (401, 403): - self.module.fail_json(msg="Failed to retrieve metadata from AWS: {0}".format(info["msg"]), response=info) + self.module.fail_json(msg=f"Failed to retrieve metadata from AWS: {info['msg']}", response=info) elif info.get("status") not in (200, 404): time.sleep(3) # request went bad, retry once then raise - self.module.warn("Retrying query to metadata service. First attempt failed: {0}".format(info["msg"])) + self.module.warn(f"Retrying query to metadata service. First attempt failed: {info['msg']}") response, info = fetch_url(self.module, encoded_url, headers=headers, force=True) if info.get("status") not in (200, 404): # fail out now - self.module.fail_json( - msg="Failed to retrieve metadata from AWS: {0}".format(info["msg"]), response=info - ) + self.module.fail_json(msg=f"Failed to retrieve metadata from AWS: {info['msg']}", response=info) if response and info["status"] < 400: data = response.read() if "user-data" in encoded_url: @@ -585,15 +583,15 @@ def fetch(self, uri, recurse=True): content = self._fetch(new_uri) if field == "security-groups" or field == "security-group-ids": sg_fields = ",".join(content.split("\n")) - self._data["%s" % (new_uri)] = sg_fields + self._data[f"{new_uri}"] = sg_fields else: try: json_dict = json.loads(content) - self._data["%s" % (new_uri)] = content + self._data[f"{new_uri}"] = content for key, value in json_dict.items(): - self._data["%s:%s" % (new_uri, key.lower())] = value + self._data[f"{new_uri}:{key.lower()}"] = value except (json_decode_error, AttributeError): - self._data["%s" % (new_uri)] = content # not a stringified JSON string + self._data[f"{new_uri}"] = content # not a stringified JSON string def fix_invalid_varnames(self, data): """Change ':'' and '-' to '_' to ensure valid template variable names""" @@ -612,19 +610,15 @@ def fetch_session_token(self, uri_token): response, info = fetch_url(self.module, uri_token, method="PUT", headers=headers, force=True) if info.get("status") == 403: - self.module.fail_json( - msg="Failed to retrieve metadata token from AWS: {0}".format(info["msg"]), response=info - ) + self.module.fail_json(msg=f"Failed to retrieve metadata token from AWS: {info['msg']}", response=info) elif info.get("status") not in (200, 404): time.sleep(3) # request went bad, retry once then raise - self.module.warn("Retrying query to metadata service. First attempt failed: {0}".format(info["msg"])) + self.module.warn(f"Retrying query to metadata service. First attempt failed: {info['msg']}") response, info = fetch_url(self.module, uri_token, method="PUT", headers=headers, force=True) if info.get("status") not in (200, 404): # fail out now - self.module.fail_json( - msg="Failed to retrieve metadata token from AWS: {0}".format(info["msg"]), response=info - ) + self.module.fail_json(msg=f"Failed to retrieve metadata token from AWS: {info['msg']}", response=info) if response: token_data = response.read() else: diff --git a/plugins/modules/s3_object.py b/plugins/modules/s3_object.py index 8f36df398f0..8fc9c8564cd 100644 --- a/plugins/modules/s3_object.py +++ b/plugins/modules/s3_object.py @@ -1381,9 +1381,9 @@ def s3_object_do_copy(module, connection, connection_v4, s3_vars): changed |= updated number_keys_updated += 1 if updated else 0 - msg = "object(s) from buckets '{0}' and '{1}' are the same.".format(src_bucket, s3_vars["bucket"]) + msg = f"object(s) from buckets '{src_bucket}' and '{s3_vars['bucket']}' are the same." if number_keys_updated: - msg = "{0} copied into bucket '{1}'".format(number_keys_updated, s3_vars["bucket"]) + msg = f"{number_keys_updated} copied into bucket '{s3_vars['bucket']}'" module.exit_json(changed=changed, msg=msg) else: # copy single object from source bucket into destination bucket