From 5de3dbbf6d47ef156c2e14a4c81f3d756bf19732 Mon Sep 17 00:00:00 2001 From: Nadir Date: Sun, 4 Sep 2016 08:45:35 +0100 Subject: [PATCH] Added redrive policy options (#2245) --- .../modules/extras/cloud/amazon/sqs_queue.py | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/extras/cloud/amazon/sqs_queue.py b/lib/ansible/modules/extras/cloud/amazon/sqs_queue.py index a16db036b01..d00a3b638ff 100644 --- a/lib/ansible/modules/extras/cloud/amazon/sqs_queue.py +++ b/lib/ansible/modules/extras/cloud/amazon/sqs_queue.py @@ -25,6 +25,7 @@ version_added: "2.0" author: - Alan Loi (@loia) - Fernando Jose Pando (@nand0p) + - Nadir Lloret (@nadirollo) requirements: - "boto >= 2.33.0" options: @@ -69,13 +70,19 @@ options: required: false default: null version_added: "2.1" + redrive_policy: + description: + - json dict with the redrive_policy (see example) + required: false + default: null + version_added: "2.2" extends_documentation_fragment: - aws - ec2 """ EXAMPLES = ''' -# Create SQS queue +# Create SQS queue with redrive policy - sqs_queue: name: my-queue region: ap-southeast-2 @@ -85,6 +92,9 @@ EXAMPLES = ''' delivery_delay: 30 receive_message_wait_time: 20 policy: "{{ json_dict }}" + redrive_policy: + maxReceiveCount: 5 + deadLetterTargetArn: arn:aws:sqs:eu-west-1:123456789012:my-dead-queue # Delete SQS queue - sqs_queue: @@ -112,6 +122,7 @@ def create_or_update_sqs_queue(connection, module): delivery_delay=module.params.get('delivery_delay'), receive_message_wait_time=module.params.get('receive_message_wait_time'), policy=module.params.get('policy'), + redrive_policy=module.params.get('redrive_policy') ) result = dict( @@ -147,7 +158,8 @@ def update_sqs_queue(queue, maximum_message_size=None, delivery_delay=None, receive_message_wait_time=None, - policy=None): + policy=None, + redrive_policy=None): changed = False changed = set_queue_attribute(queue, 'VisibilityTimeout', default_visibility_timeout, @@ -162,6 +174,8 @@ def update_sqs_queue(queue, check_mode=check_mode) or changed changed = set_queue_attribute(queue, 'Policy', policy, check_mode=check_mode) or changed + changed = set_queue_attribute(queue, 'RedrivePolicy', redrive_policy, + check_mode=check_mode) or changed return changed @@ -175,7 +189,7 @@ def set_queue_attribute(queue, attribute, value, check_mode=False): existing_value = '' # convert dict attributes to JSON strings (sort keys for comparing) - if attribute is 'Policy': + if attribute in ['Policy', 'RedrivePolicy']: value = json.dumps(value, sort_keys=True) if existing_value: existing_value = json.dumps(json.loads(existing_value), sort_keys=True) @@ -224,6 +238,7 @@ def main(): delivery_delay=dict(type='int'), receive_message_wait_time=dict(type='int'), policy=dict(type='dict', required=False), + redrive_policy=dict(type='dict', required=False), )) module = AnsibleModule(