Skip to content

Commit

Permalink
update lookup plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ozbillwang committed Apr 14, 2017
1 parent 47b6e86 commit 0092bdc
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lookup/ssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,38 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

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

try:
import botocore
from botocore.exceptions import ClientError
import boto3
HAS_BOTO3 = True
except ImportError:
HAS_BOTO3 = False

from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase
pass # will be captured by imported HAS_BOTO3


class LookupModule(LookupBase):
def run(self, terms, variables, **kwargs):

ret = {}
response = {}

if not HAS_BOTO3:
raise AnsibleError('botocore and boto3 are required.')

client = boto3.client('ssm')

ret = {}

for term in terms:
try:
response = client.get_parameters(
Names=[term],
WithDecryption=True
)
except botocore.exceptions.ClientError as e:
module.fail_json(msg=str(e))
except ClientError, e:
module.fail_json(msg=e.message, exception=traceback.format_exc(),
**camel_dict_to_snake_dict(e.response))

ret.update(response)

if ret['Parameters']:
Expand Down

0 comments on commit 0092bdc

Please sign in to comment.