Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #954 backport][stable-4] Minor Linting fixups - 2022-08-05 #960

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions plugins/modules/cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
version_added: 1.0.0
short_description: Create or delete an AWS CloudFormation stack
description:
- Launches or updates an AWS CloudFormation stack and waits for it complete.
notes:
- CloudFormation features change often, and this module tries to keep up. That means your botocore version should be fresh.
The version listed in the requirements is the oldest version that works with the module as a whole.
Some features may require recent versions, and we do not pinpoint a minimum version for each feature.
Instead of relying on the minimum version, keep botocore up to date. AWS is always releasing features and fixing bugs.
- Launches or updates an AWS CloudFormation stack and waits for it complete.
options:
stack_name:
description:
Expand Down Expand Up @@ -118,12 +113,12 @@
type: str
role_arn:
description:
- The role that AWS CloudFormation assumes to create the stack. See the AWS CloudFormation Service Role
docs U(https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-servicerole.html)
- The role that AWS CloudFormation assumes to create the stack. See the AWS CloudFormation Service Role
docs U(https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-servicerole.html)
type: str
termination_protection:
description:
- Enable or disable termination protection on the stack.
- Enable or disable termination protection on the stack.
type: bool
template_body:
description:
Expand All @@ -135,40 +130,41 @@
type: str
events_limit:
description:
- Maximum number of CloudFormation events to fetch from a stack when creating or updating it.
- Maximum number of CloudFormation events to fetch from a stack when creating or updating it.
default: 200
type: int
backoff_delay:
description:
- Number of seconds to wait for the next retry.
- Number of seconds to wait for the next retry.
default: 3
type: int
required: False
backoff_max_delay:
description:
- Maximum amount of time to wait between retries.
- Maximum amount of time to wait between retries.
default: 30
type: int
required: False
backoff_retries:
description:
- Number of times to retry operation.
- AWS API throttling mechanism fails CloudFormation module so we have to retry a couple of times.
- Number of times to retry operation.
- AWS API throttling mechanism fails CloudFormation module so we have to retry a couple of times.
default: 10
type: int
required: False
capabilities:
description:
- Specify capabilities that stack template contains.
- Valid values are C(CAPABILITY_IAM), C(CAPABILITY_NAMED_IAM) and C(CAPABILITY_AUTO_EXPAND).
- Specify capabilities that stack template contains.
- Valid values are C(CAPABILITY_IAM), C(CAPABILITY_NAMED_IAM) and C(CAPABILITY_AUTO_EXPAND).
type: list
elements: str
default: [ CAPABILITY_IAM, CAPABILITY_NAMED_IAM ]

author: "James S. Martin (@jsmartin)"
author:
- "James S. Martin (@jsmartin)"
extends_documentation_fragment:
- amazon.aws.aws
- amazon.aws.ec2
- amazon.aws.aws
- amazon.aws.ec2
'''

EXAMPLES = '''
Expand Down Expand Up @@ -577,7 +573,7 @@ def check_mode_changeset(module, stack_params, cfn):

try:
change_set = cfn.create_change_set(aws_retry=True, **stack_params)
for i in range(60): # total time 5 min
for _i in range(60): # total time 5 min
description = cfn.describe_change_set(aws_retry=True, ChangeSetName=change_set['Id'])
if description['Status'] in ('CREATE_COMPLETE', 'FAILED'):
break
Expand Down
39 changes: 17 additions & 22 deletions plugins/modules/ec2_eni.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@
version_added: 1.0.0
short_description: Create and optionally attach an Elastic Network Interface (ENI) to an instance
description:
- Create and optionally attach an Elastic Network Interface (ENI) to an instance. If an ENI ID or private_ip is
provided, the existing ENI (if any) will be modified. The 'attached' parameter controls the attachment status
of the network interface.
- Create and optionally attach an Elastic Network Interface (ENI) to an instance.
- If I(eni_id) or I(private_ip) is provided, the existing ENI (if any) will be modified.
- The I(attached) parameter controls the attachment status of the network interface.
author:
- "Rob White (@wimnat)"
- "Mike Healey (@healem)"
- "Rob White (@wimnat)"
- "Mike Healey (@healem)"
options:
eni_id:
description:
- The ID of the ENI (to modify).
- If I(eni_id=None) and I(state=present), a new eni will be created.
- If I(eni_id=None) and I(state=present), a new ENI will be created.
type: str
instance_id:
description:
- Instance ID that you wish to attach ENI to.
- Since version 2.2, use the I(attached) parameter to attach or detach an ENI. Prior to 2.2, to detach an ENI from an instance, use C(None).
type: str
private_ip_address:
description:
Expand All @@ -43,8 +42,8 @@
type: str
security_groups:
description:
- List of security groups associated with the interface. Only used when I(state=present).
- Since version 2.2, you can specify security groups by ID or by name or a combination of both. Prior to 2.2, you can specify only by ID.
- List of security groups associated with the interface.
- Ignored when I(state=absent).
type: list
elements: str
state:
Expand Down Expand Up @@ -84,7 +83,7 @@
secondary_private_ip_addresses:
description:
- A list of IP addresses to assign as secondary IP addresses to the network interface.
This option is mutually exclusive of I(secondary_private_ip_address_count)
- This option is mutually exclusive of I(secondary_private_ip_address_count).
required: false
type: list
elements: str
Expand All @@ -96,7 +95,8 @@
type: bool
secondary_private_ip_address_count:
description:
- The number of secondary IP addresses to assign to the network interface. This option is mutually exclusive of I(secondary_private_ip_addresses)
- The number of secondary IP addresses to assign to the network interface.
- This option is mutually exclusive of I(secondary_private_ip_addresses).
required: false
type: int
allow_reassignment:
Expand All @@ -115,14 +115,13 @@
required: false
type: str
extends_documentation_fragment:
- amazon.aws.aws
- amazon.aws.ec2
- amazon.aws.tags
- amazon.aws.aws
- amazon.aws.ec2
- amazon.aws.tags
notes:
- This module identifies and ENI based on either the I(eni_id), a combination of I(private_ip_address) and I(subnet_id),
or a combination of I(instance_id) and I(device_id). Any of these options will let you specify a particular ENI.
- Support for I(tags) and I(purge_tags) was added in release 1.3.0.
- This module identifies and ENI based on either the I(eni_id), a combination of I(private_ip_address) and I(subnet_id),
or a combination of I(instance_id) and I(device_id). Any of these options will let you specify a particular ENI.
- Support for I(tags) and I(purge_tags) was added in release 1.3.0.
'''

EXAMPLES = '''
Expand Down Expand Up @@ -341,7 +340,6 @@ def get_eni_info(interface):


def correct_ips(connection, ip_list, module, eni_id):
all_there = True
eni = describe_eni(connection, module, eni_id)
private_addresses = set()
if "PrivateIpAddresses" in eni:
Expand All @@ -354,7 +352,6 @@ def correct_ips(connection, ip_list, module, eni_id):


def absent_ips(connection, ip_list, module, eni_id):
all_there = True
eni = describe_eni(connection, module, eni_id)
private_addresses = set()
if "PrivateIpAddresses" in eni:
Expand Down Expand Up @@ -498,7 +495,6 @@ def modify_eni(connection, module, eni):
device_index = module.params.get("device_index")
description = module.params.get('description')
security_groups = module.params.get('security_groups')
force_detach = module.params.get("force_detach")
source_dest_check = module.params.get("source_dest_check")
delete_on_termination = module.params.get("delete_on_termination")
secondary_private_ip_addresses = module.params.get("secondary_private_ip_addresses")
Expand Down Expand Up @@ -696,7 +692,6 @@ def detach_eni(connection, eni, module):
if module.check_mode:
module.exit_json(changed=True, msg="Would have detached ENI if not in check mode.")

attached = module.params.get("attached")
eni_id = eni["NetworkInterfaceId"]

force_detach = module.params.get("force_detach")
Expand Down
12 changes: 6 additions & 6 deletions plugins/modules/ec2_eni_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
---
module: ec2_eni_info
version_added: 1.0.0
short_description: Gather information about ec2 ENI interfaces in AWS
short_description: Gather information about EC2 ENI interfaces in AWS
description:
- Gather information about ec2 ENI interfaces in AWS.
author: "Rob White (@wimnat)"
- Gather information about EC2 ENI interfaces in AWS.
author:
- "Rob White (@wimnat)"
options:
eni_id:
description:
Expand All @@ -28,9 +29,8 @@
- This option is mutually exclusive of I(eni_id).
type: dict
extends_documentation_fragment:
- amazon.aws.aws
- amazon.aws.ec2

- amazon.aws.aws
- amazon.aws.ec2
'''

EXAMPLES = '''
Expand Down
20 changes: 7 additions & 13 deletions plugins/modules/ec2_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- "Razique Mahroua (@Razique)"
short_description: Maintain an ec2 VPC security group
description:
- Maintains ec2 security groups.
- Maintains EC2 security groups.
options:
name:
description:
Expand Down Expand Up @@ -46,9 +46,6 @@
- List of firewall inbound rules to enforce in this group (see example). If none are supplied,
no inbound rules will be enabled. Rules list may include its own name in I(group_name).
This allows idempotent loopback additions (e.g. allow group to access itself).
Rule sources list support was added in version 2.4. This allows to define multiple sources per
source type as well as multiple source types per rule. Prior to 2.4 an individual source is allowed.
In version 2.5 support for rule descriptions was added.
required: false
type: list
elements: dict
Expand Down Expand Up @@ -132,8 +129,6 @@
description:
- List of firewall outbound rules to enforce in this group (see example). If none are supplied,
a default all-out rule is assumed. If an empty list is supplied, no outbound rules will be enabled.
Rule Egress sources list support was added in version 2.4. In version 2.5 support for rule descriptions
was added.
required: false
type: list
elements: dict
Expand Down Expand Up @@ -237,9 +232,9 @@
type: bool

extends_documentation_fragment:
- amazon.aws.aws
- amazon.aws.ec2
- amazon.aws.tags
- amazon.aws.aws
- amazon.aws.ec2
- amazon.aws.tags


notes:
Expand Down Expand Up @@ -1054,7 +1049,7 @@ def wait_for_rule_propagation(module, client, group, desired_ingress, desired_eg
tries = 6

def await_rules(group, desired_rules, purge, rule_key):
for i in range(tries):
for _i in range(tries):
current_rules = set(sum([list(rule_from_group_permission(p)) for p in group[rule_key]], []))
if purge and len(current_rules ^ set(desired_rules)) == 0:
return group
Expand Down Expand Up @@ -1352,8 +1347,8 @@ def main():
current_ingress = sum([list(rule_from_group_permission(p)) for p in group['IpPermissions']], [])
current_egress = sum([list(rule_from_group_permission(p)) for p in group['IpPermissionsEgress']], [])

for new_rules, rule_type, named_tuple_rule_list in [(rules, 'in', named_tuple_ingress_list),
(rules_egress, 'out', named_tuple_egress_list)]:
for new_rules, _rule_type, named_tuple_rule_list in [(rules, 'in', named_tuple_ingress_list),
(rules_egress, 'out', named_tuple_egress_list)]:
if new_rules is None:
continue
for rule in new_rules:
Expand Down Expand Up @@ -1437,7 +1432,6 @@ def main():

# Revoke old rules
changed |= remove_old_permissions(client, module, revoke_ingress, revoke_egress, group['GroupId'])
rule_msg = 'Revoking {0}, and egress {1}'.format(revoke_ingress, revoke_egress)

new_ingress_permissions = [to_permission(r) for r in (set(named_tuple_ingress_list) - set(current_ingress))]
new_ingress_permissions = rules_to_permissions(set(named_tuple_ingress_list) - set(current_ingress))
Expand Down
7 changes: 3 additions & 4 deletions plugins/modules/ec2_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ def add_or_update_instance_profile(instance, desired_profile_name):
# check for InvalidAssociationID.NotFound
module.fail_json_aws(e, "Could not find instance profile association")
try:
resp = client.replace_iam_instance_profile_association(
client.replace_iam_instance_profile_association(
aws_retry=True,
AssociationId=association['IamInstanceProfileAssociations'][0]['AssociationId'],
IamInstanceProfile={'Arn': determine_iam_role(desired_profile_name)}
Expand All @@ -1053,7 +1053,7 @@ def add_or_update_instance_profile(instance, desired_profile_name):
if not instance_profile_setting and desired_profile_name:
# create association
try:
resp = client.associate_iam_instance_profile(
client.associate_iam_instance_profile(
aws_retry=True,
IamInstanceProfile={'Arn': determine_iam_role(desired_profile_name)},
InstanceId=instance['InstanceId']
Expand Down Expand Up @@ -1507,7 +1507,6 @@ def change_network_attachments(instance, params):


def find_instances(ids=None, filters=None):
paginator = client.get_paginator('describe_instances')
sanitized_filters = dict()

if ids:
Expand Down Expand Up @@ -1855,7 +1854,7 @@ def enforce_count(existing_matches, module, desired_module_state):
module.exit_json(changed=True, msg='Would have terminated following instances if not in check mode {0}'.format(terminate_ids))
# terminate instances
try:
result = client.terminate_instances(aws_retry=True, InstanceIds=terminate_ids)
client.terminate_instances(aws_retry=True, InstanceIds=terminate_ids)
await_instances(terminate_ids, desired_module_state='terminated', force_wait=True)
except is_boto3_error_code('InvalidInstanceID.NotFound'):
pass
Expand Down
Loading