diff options
author | Rob <wimnat@users.noreply.github.com> | 2016-09-20 07:44:09 +1000 |
---|---|---|
committer | Ryan Brown <sb@ryansb.com> | 2016-09-19 17:44:09 -0400 |
commit | 99c44d9640575b711672a70b781101994d689492 (patch) | |
tree | fd28cabb3e8f62ac1f5c9f69926f94c1e112fe5e /cloud/amazon | |
parent | ddbd63c8a696d441d4908e16b5ea166bf962fcb1 (diff) | |
download | ansible-modules-extras-99c44d9640575b711672a70b781101994d689492.tar.gz |
Modification of describe_gateways key so that it is consistent with w… (#2936)
* Modification of describe_gateways key so that it is consistent with what create_gateway returns.
Also added AnsibleModule spec to require bgp_ip on state=present as defined in the doc
* Don't remove CustomerGateways key to preserve backward compatibility
Diffstat (limited to 'cloud/amazon')
-rw-r--r-- | cloud/amazon/ec2_customer_gateway.py | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/cloud/amazon/ec2_customer_gateway.py b/cloud/amazon/ec2_customer_gateway.py index 072fec71..871513d9 100644 --- a/cloud/amazon/ec2_customer_gateway.py +++ b/cloud/amazon/ec2_customer_gateway.py @@ -44,6 +44,9 @@ options: required: false default: present choices: [ 'present', 'absent' ] +notes: + - Return values contain customer_gateway and customer_gateways keys which are identical dicts. You should use + customer_gateway. See U(https://github.com/ansible/ansible-modules-extras/issues/2773) for details. extends_documentation_fragment: - aws - ec2 @@ -182,18 +185,24 @@ class Ec2CustomerGatewayManager: ) return response + def main(): argument_spec = ec2_argument_spec() argument_spec.update( dict( - bgp_asn = dict(required=False, type='int'), - ip_address = dict(required=True), - name = dict(required=True), - state = dict(default='present', choices=['present', 'absent']), + bgp_asn=dict(required=False, type='int'), + ip_address=dict(required=True), + name=dict(required=True), + state=dict(default='present', choices=['present', 'absent']), ) ) - module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True, + required_if=[ + ('state', 'present', ['bgp_arn']) + ] + ) if not HAS_BOTOCORE: module.fail_json(msg='botocore is required.') @@ -208,19 +217,22 @@ def main(): name = module.params.get('name') existing = gw_mgr.describe_gateways(module.params['ip_address']) + # describe_gateways returns a key of CustomerGateways where as create_gateway returns a + # key of CustomerGateway. For consistency, change it here + existing['CustomerGateway'] = existing['CustomerGateways'] results = dict(changed=False) if module.params['state'] == 'present': - if existing['CustomerGateways']: - results['gateway']=existing - if existing['CustomerGateways'][0]['Tags']: - tag_array = existing['CustomerGateways'][0]['Tags'] + if existing['CustomerGateway']: + results['gateway'] = existing + if existing['CustomerGateway'][0]['Tags']: + tag_array = existing['CustomerGateway'][0]['Tags'] for key, value in enumerate(tag_array): if value['Key'] == 'Name': current_name = value['Value'] if current_name != name: results['name'] = gw_mgr.tag_cgw_name( - results['gateway']['CustomerGateways'][0]['CustomerGatewayId'], + results['gateway']['CustomerGateway'][0]['CustomerGatewayId'], module.params['name'], ) results['changed'] = True @@ -237,11 +249,11 @@ def main(): results['changed'] = True elif module.params['state'] == 'absent': - if existing['CustomerGateways']: - results['gateway']=existing + if existing['CustomerGateway']: + results['gateway'] = existing if not module.check_mode: results['gateway'] = gw_mgr.ensure_cgw_absent( - existing['CustomerGateways'][0]['CustomerGatewayId'] + existing['CustomerGateway'][0]['CustomerGatewayId'] ) results['changed'] = True |