Skip to content

Commit

Permalink
ansible-lint (documentation) cleanup for plugins/ (#1900)
Browse files Browse the repository at this point in the history
ansible-lint (documentation) cleanup for plugins/

SUMMARY
Fixes an array of ansible-lint failures in plugins/
Adds ansible-lint plugins/ to tox -m lint

ISSUE TYPE

Docs Pull Request

COMPONENT NAME

plugins/

ADDITIONAL INFORMATION

docs changes only (no changelog fragment needed)

Reviewed-by: Alina Buzachis
(cherry picked from commit b8bda83)
Co-authored-by: Mark Chappell <[email protected]>
  • Loading branch information
patchback[bot] and tremble authored Dec 13, 2023
1 parent bc64dcf commit fa38e47
Show file tree
Hide file tree
Showing 54 changed files with 380 additions and 367 deletions.
14 changes: 4 additions & 10 deletions plugins/callback/aws_resource_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,10 @@
[defaults]
callback_whitelist = aws_resource_actions
sample output: >
#
# AWS ACTIONS: ['s3:PutBucketAcl', 's3:HeadObject', 's3:DeleteObject', 's3:PutObjectAcl', 's3:CreateMultipartUpload',
# 's3:DeleteBucket', 's3:GetObject', 's3:DeleteObjects', 's3:CreateBucket', 's3:CompleteMultipartUpload',
# 's3:ListObjectsV2', 's3:HeadBucket', 's3:UploadPart', 's3:PutObject']
#
sample output: >
#
# AWS ACTIONS: ['ec2:DescribeVpcAttribute', 'ec2:DescribeVpcClassicLink', 'ec2:ModifyVpcAttribute', 'ec2:CreateTags',
# 'sts:GetCallerIdentity', 'ec2:DescribeSecurityGroups', 'ec2:DescribeTags', 'ec2:DescribeVpcs', 'ec2:CreateVpc']
#
#
# AWS ACTIONS: ['s3:PutBucketAcl', 's3:HeadObject', 's3:DeleteObject', 's3:PutObjectAcl', 's3:CreateMultipartUpload',
# 's3:DeleteBucket', 's3:GetObject', 's3:DeleteObjects', 's3:CreateBucket', 's3:CompleteMultipartUpload',
# 's3:ListObjectsV2', 's3:HeadBucket', 's3:UploadPart', 's3:PutObject']
"""

from ansible.module_utils._text import to_native
Expand Down
34 changes: 23 additions & 11 deletions plugins/inventory/aws_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@
regions:
- us-east-1
---
# Example using filters, ignoring permission errors, and specifying the hostname precedence
plugin: amazon.aws.aws_ec2
# The values for profile, access key, secret key and token can be hardcoded like:
Expand All @@ -165,15 +167,16 @@
- us-east-1
- us-east-2
filters:
# All instances with their `Environment` tag set to `dev`
tag:Environment: dev
## All instances with their `Environment` tag set to `dev`
# tag:Environment: dev
# All dev and QA hosts
tag:Environment:
- dev
- qa
instance.group-id: sg-xxxxxxxx
# Ignores 403 errors rather than failing
strict_permissions: False
strict_permissions: false
# Note: I(hostnames) sets the inventory_hostname. To modify ansible_host without modifying
# inventory_hostname use compose (see example below).
hostnames:
Expand All @@ -189,15 +192,17 @@
prefix: 'aws'
# Returns all the hostnames for a given instance
allow_duplicated_hosts: False
allow_duplicated_hosts: false
---
# Example using constructed features to create groups and set ansible_host
plugin: amazon.aws.aws_ec2
regions:
- us-east-1
- us-west-1
# keyed_groups may be used to create custom groups
strict: False
strict: false
keyed_groups:
# Add e.g. x86_64 hosts to an arch_x86_64 group
- prefix: arch
Expand Down Expand Up @@ -227,19 +232,23 @@
# (note: this does not modify inventory_hostname, which is set via I(hostnames))
ansible_host: private_ip_address
---
# Example using include_filters and exclude_filters to compose the inventory.
plugin: amazon.aws.aws_ec2
regions:
- us-east-1
- us-west-1
include_filters:
- tag:Name:
- 'my_second_tag'
- tag:Name:
- 'my_third_tag'
- tag:Name:
- 'my_second_tag'
- tag:Name:
- 'my_third_tag'
exclude_filters:
- tag:Name:
- 'my_first_tag'
- tag:Name:
- 'my_first_tag'
---
# Example using groups to assign the running hosts to a group based on vpc_id
plugin: amazon.aws.aws_ec2
Expand All @@ -257,6 +266,9 @@
ansible_host: public_dns_name
groups:
libvpc: vpc_id == 'vpc-####'
---
# Define prefix and suffix for host variables coming from AWS.
plugin: amazon.aws.aws_ec2
regions:
Expand Down
1 change: 0 additions & 1 deletion plugins/lookup/aws_account_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
account_details: "{{ lookup('aws_account_attribute', wantlist='true') }}"
# {'default-vpc': ['vpc-xxxxxxxx'], 'max-elastic-ips': ['5'], 'max-instances': ['20'],
# 'supported-platforms': ['VPC', 'EC2'], 'vpc-max-elastic-ips': ['5'], 'vpc-max-security-groups-per-interface': ['5']}
"""

RETURN = r"""
Expand Down
13 changes: 6 additions & 7 deletions plugins/lookup/aws_service_ip_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
vars:
ec2_ranges: "{{ lookup('aws_service_ip_ranges', region='ap-southeast-2', service='EC2', wantlist=True) }}"
tasks:
- name: "use list return option and iterate as a loop"
debug: msg="{% for cidr in ec2_ranges %}{{ cidr }} {% endfor %}"
# "52.62.0.0/15 52.64.0.0/17 52.64.128.0/17 52.65.0.0/16 52.95.241.0/24 52.95.255.16/28 54.66.0.0/16 "
- name: "use list return option and iterate as a loop"
debug: msg="{% for cidr in ec2_ranges %}{{ cidr }} {% endfor %}"
# "52.62.0.0/15 52.64.0.0/17 52.64.128.0/17 52.65.0.0/16 52.95.241.0/24 52.95.255.16/28 54.66.0.0/16 "
- name: "Pull S3 IP ranges, and print the default return style"
debug: msg="{{ lookup('aws_service_ip_ranges', region='us-east-1', service='S3') }}"
# "52.92.16.0/20,52.216.0.0/15,54.231.0.0/17"
- name: "Pull S3 IP ranges, and print the default return style"
debug: msg="{{ lookup('aws_service_ip_ranges', region='us-east-1', service='S3') }}"
# "52.92.16.0/20,52.216.0.0/15,54.231.0.0/17"
"""

RETURN = r"""
Expand Down
58 changes: 29 additions & 29 deletions plugins/lookup/secretsmanager_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,39 +78,39 @@
"""

EXAMPLES = r"""
- name: lookup secretsmanager secret in the current region
debug: msg="{{ lookup('amazon.aws.aws_secret', '/path/to/secrets', bypath=true) }}"
- name: lookup secretsmanager secret in the current region
debug: msg="{{ lookup('amazon.aws.aws_secret', '/path/to/secrets', bypath=true) }}"
- name: Create RDS instance with aws_secret lookup for password param
rds:
command: create
instance_name: app-db
db_engine: MySQL
size: 10
instance_type: db.m1.small
username: dbadmin
password: "{{ lookup('amazon.aws.aws_secret', 'DbSecret') }}"
tags:
Environment: staging
- name: Create RDS instance with aws_secret lookup for password param
rds:
command: create
instance_name: app-db
db_engine: MySQL
size: 10
instance_type: db.m1.small
username: dbadmin
password: "{{ lookup('amazon.aws.aws_secret', 'DbSecret') }}"
tags:
Environment: staging
- name: skip if secret does not exist
debug: msg="{{ lookup('amazon.aws.aws_secret', 'secret-not-exist', on_missing='skip')}}"
- name: skip if secret does not exist
debug: msg="{{ lookup('amazon.aws.aws_secret', 'secret-not-exist', on_missing='skip')}}"
- name: warn if access to the secret is denied
debug: msg="{{ lookup('amazon.aws.aws_secret', 'secret-denied', on_denied='warn')}}"
- name: warn if access to the secret is denied
debug: msg="{{ lookup('amazon.aws.aws_secret', 'secret-denied', on_denied='warn')}}"
- name: lookup secretsmanager secret in the current region using the nested feature
debug: msg="{{ lookup('amazon.aws.aws_secret', 'secrets.environments.production.password', nested=true) }}"
# The secret can be queried using the following syntax: `aws_secret_object_name.key1.key2.key3`.
# If an object is of the form `{"key1":{"key2":{"key3":1}}}` the query would return the value `1`.
- name: lookup secretsmanager secret in a specific region using specified region and aws profile using nested feature
debug: >
msg="{{ lookup('amazon.aws.aws_secret', 'secrets.environments.production.password', region=region, profile=aws_profile,
access_key=aws_access_key, secret_key=aws_secret_key, nested=true) }}"
# The secret can be queried using the following syntax: `aws_secret_object_name.key1.key2.key3`.
# If an object is of the form `{"key1":{"key2":{"key3":1}}}` the query would return the value `1`.
# Region is the AWS region where the AWS secret is stored.
# AWS_profile is the aws profile to use, that has access to the AWS secret.
- name: lookup secretsmanager secret in the current region using the nested feature
debug: msg="{{ lookup('amazon.aws.aws_secret', 'secrets.environments.production.password', nested=true) }}"
# The secret can be queried using the following syntax: `aws_secret_object_name.key1.key2.key3`.
# If an object is of the form `{"key1":{"key2":{"key3":1}}}` the query would return the value `1`.
- name: lookup secretsmanager secret in a specific region using specified region and aws profile using nested feature
debug: >
msg="{{ lookup('amazon.aws.aws_secret', 'secrets.environments.production.password', region=region, profile=aws_profile,
access_key=aws_access_key, secret_key=aws_secret_key, nested=true) }}"
# The secret can be queried using the following syntax: `aws_secret_object_name.key1.key2.key3`.
# If an object is of the form `{"key1":{"key2":{"key3":1}}}` the query would return the value `1`.
# Region is the AWS region where the AWS secret is stored.
# AWS_profile is the aws profile to use, that has access to the AWS secret.
"""

RETURN = r"""
Expand Down
4 changes: 3 additions & 1 deletion plugins/lookup/ssm_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@
debug: msg="{{ lookup('amazon.aws.aws_ssm', 'Hello', profile='myprofile' ) }}"
- name: lookup ssm parameter store using explicit aws credentials
debug: msg="{{ lookup('amazon.aws.aws_ssm', 'Hello', access_key=my_aws_access_key, secret_key=my_aws_secret_key, session_token=my_session_token ) }}" # noqa: E501
debug:
msg: >-
{{ lookup('amazon.aws.aws_ssm', 'Hello', access_key=my_aws_access_key, secret_key=my_aws_secret_key, session_token=my_session_token ) }}"
- name: lookup ssm parameter store with all options
debug: msg="{{ lookup('amazon.aws.aws_ssm', 'Hello', decrypt=false, region='us-east-2', profile='myprofile') }}"
Expand Down
48 changes: 24 additions & 24 deletions plugins/modules/autoscaling_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,13 @@
- amazon.aws.autoscaling_group:
name: special
load_balancers: [ 'lb1', 'lb2' ]
availability_zones: [ 'eu-west-1a', 'eu-west-1b' ]
load_balancers: ['lb1', 'lb2']
availability_zones: ['eu-west-1a', 'eu-west-1b']
launch_config_name: 'lc-1'
min_size: 1
max_size: 10
desired_capacity: 5
vpc_zone_identifier: [ 'subnet-abcd1234', 'subnet-1a2b3c4d' ]
vpc_zone_identifier: ['subnet-abcd1234', 'subnet-1a2b3c4d']
tags:
- environment: production
propagate_at_launch: false
Expand Down Expand Up @@ -396,8 +396,8 @@
health_check_period: 60
health_check_type: ELB
replace_instances:
- i-b345231
- i-24c2931
- i-b345231
- i-24c2931
min_size: 5
max_size: 5
desired_capacity: 5
Expand All @@ -407,16 +407,16 @@
- amazon.aws.autoscaling_group:
name: special
load_balancers: [ 'lb1', 'lb2' ]
availability_zones: [ 'eu-west-1a', 'eu-west-1b' ]
load_balancers: ['lb1', 'lb2']
availability_zones: ['eu-west-1a', 'eu-west-1b']
launch_template:
version: '1'
launch_template_name: 'lt-example'
launch_template_id: 'lt-123456'
version: '1'
launch_template_name: 'lt-example'
launch_template_id: 'lt-123456'
min_size: 1
max_size: 10
desired_capacity: 5
vpc_zone_identifier: [ 'subnet-abcd1234', 'subnet-1a2b3c4d' ]
vpc_zone_identifier: ['subnet-abcd1234', 'subnet-1a2b3c4d']
tags:
- environment: production
propagate_at_launch: false
Expand All @@ -425,24 +425,24 @@
- amazon.aws.autoscaling_group:
name: special
load_balancers: [ 'lb1', 'lb2' ]
availability_zones: [ 'eu-west-1a', 'eu-west-1b' ]
load_balancers: ['lb1', 'lb2']
availability_zones: ['eu-west-1a', 'eu-west-1b']
launch_template:
version: '1'
launch_template_name: 'lt-example'
launch_template_id: 'lt-123456'
version: '1'
launch_template_name: 'lt-example'
launch_template_id: 'lt-123456'
mixed_instances_policy:
instance_types:
- t3a.large
- t3.large
- t2.large
instances_distribution:
on_demand_percentage_above_base_capacity: 0
spot_allocation_strategy: capacity-optimized
instance_types:
- t3a.large
- t3.large
- t2.large
instances_distribution:
on_demand_percentage_above_base_capacity: 0
spot_allocation_strategy: capacity-optimized
min_size: 1
max_size: 10
desired_capacity: 5
vpc_zone_identifier: [ 'subnet-abcd1234', 'subnet-1a2b3c4d' ]
vpc_zone_identifier: ['subnet-abcd1234', 'subnet-1a2b3c4d']
tags:
- environment: production
propagate_at_launch: false
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/backup_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
backup_plan_name: 1111f877-1ecf-4d79-9718-a861cd09df3b
iam_role_arn: arn:aws:iam::111122223333:role/system-backup
resources:
- arn:aws:elasticfilesystem:*:*:file-system/*
- arn:aws:elasticfilesystem:*:*:file-system/*
"""


Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/backup_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,23 @@
resource: "{{ backup_resource_arn }}"
state: absent
tags:
CamelCaseKey: CamelCaseValue
CamelCaseKey: CamelCaseValue
- name: Remove all tags except for specified tags
amazon.aws.backup_tag:
resource: "{{ backup_resource_arn }}"
state: absent
tags:
test_tag_key_1: tag_tag_value_1
test_tag_key_2: tag_tag_value_2
test_tag_key_1: tag_tag_value_1
test_tag_key_2: tag_tag_value_2
purge_tags: true
- name: Update value of tag key on a resource
amazon.aws.backup_tag:
resource: "{{ backup_resource_arn }}"
state: present
tags:
test_tag_key_1: tag_tag_value_NEW_1
test_tag_key_1: tag_tag_value_NEW_1
- name: Remove all of the tags on a resource
amazon.aws.backup_tag:
Expand Down
1 change: 0 additions & 1 deletion plugins/modules/backup_vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
tags:
environment: dev
Name: default
"""

RETURN = r"""
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@
template: "files/cloudformation-example.json"
template_parameters:
DBSnapshotIdentifier:
use_previous_value: True
use_previous_value: true
value: arn:aws:rds:es-east-1:123456789012:snapshot:rds:my-db-snapshot
DBName:
use_previous_value: True
use_previous_value: true
tags:
Stack: "ansible-cloudformation"
Expand Down
Loading

0 comments on commit fa38e47

Please sign in to comment.