Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Wang committed Apr 19, 2017
1 parent e5e91f0 commit 84236a8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
26 changes: 13 additions & 13 deletions library/ssm_parameter_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@

def create_update_parameter(client, module):
changed = False
reponse = {}
response = {}

args = dict(
Name=module.params.get('name'),
Expand All @@ -147,54 +147,54 @@ def create_update_parameter(client, module):
args.update(KeyId=module.params.get('key_id'))

try:
reponse = client.put_parameter(**args)
response = client.put_parameter(**args)
changed = True
except ClientError as e:
module.fail_json(msg=e.message, exception=traceback.format_exc(),
**camel_dict_to_snake_dict(e.response))

return changed, reponse
return changed, response


def get_parameter(client, module):
changed = False
reponse = {}
response = {}

try:
reponse = client.get_parameters(
response = client.get_parameters(
Names=[module.params.get('name')],
WithDecryption=module.params.get('decryption')
)
except ClientError as e:
module.fail_json(msg=e.message, exception=traceback.format_exc(),
**camel_dict_to_snake_dict(e.response))

return changed, reponse['Parameters']
return changed, response['Parameters']


def delete_parameter(client, module):
changed = False
reponse = {}
response = {}

try:
get_reponse = client.get_parameters(
get_response = client.get_parameters(
Names=[module.params.get('name')]
)
except ClientError as e:
module.fail_json(msg=e.message, exception=traceback.format_exc(),
**camel_dict_to_snake_dict(e.response))

if get_reponse['Parameters']:
if get_response['Parameters']:
try:
reponse = client.delete_parameter(
response = client.delete_parameter(
Name=module.params.get('name')
)
changed = True
except ClientError as e:
module.fail_json(msg=e.message, exception=traceback.format_exc(),
**camel_dict_to_snake_dict(e.response))

return changed, reponse
return changed, response


def main():
Expand Down Expand Up @@ -229,8 +229,8 @@ def main():
"present": create_update_parameter,
"absent": delete_parameter,
}
(changed, reponse) = invocations[state](client, module)
module.exit_json(changed=changed, response=reponse)
(changed, response) = invocations[state](client, module)
module.exit_json(changed=changed, response=response)

if __name__ == '__main__':
main()
3 changes: 2 additions & 1 deletion lookup/ssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible.module_utils.ec2 import HAS_BOTO3
import traceback
from ansible.module_utils.ec2 import HAS_BOTO3, camel_dict_to_snake_dict
from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase

Expand Down
4 changes: 2 additions & 2 deletions test/roles/test/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
description: "This is your first key"
region: us-east-1
string_type: "SecureString"
value: "World"
value: "World at us-east-1"

- name: Create or update secure key/value pair with nominated kms key
ssm_parameter_store:
Expand All @@ -31,7 +31,7 @@
value: "World"

- name: recommend to use with ssm lookup plugin
debug: msg="{{ lookup('ssm', 'hello') }}"
debug: msg="{{ lookup('ssm', 'Hello' ) }}"

- name: lookup a key which is not exist
debug: msg="{{ lookup('ssm', 'NoKey') }}"

0 comments on commit 84236a8

Please sign in to comment.