Add Amazon Elastic File System (efs) module #2305
Conversation
Thanks @ryansydnor for this PR. This PR requires revisions, either because it fails to build or by reviewer request. Please make the suggested revisions. When you are done, please comment with text 'ready_for_review' and we will put this PR back into review. [This message brought to you by your friendly Ansibull-bot.] |
@gregdek - are the travis errors show stoppers? |
Looks like we're trying to do a simple boto3 detection in travis and failing, so I would say no. |
Is the |
No. I was testing on an older version (1.9.5) and mixing boto/boto3 to connect. I've removed all dependencies on boto and tested against ansible 2.1 and boto3. Looks good! |
@gregdek - I believe we can remove the "needs_revision" label and add "community_review" (or equivalent). |
Thanks @ryansydnor :) |
Hi @ryansydnor EFS has just gone live in eu-west-1 so it would be good to get this functionality added. I'm testing this against latest devel:(ansible/ansible@216a845)
I'm using the following playbook:
|
Hi @jonhadfield! First of all, thanks so much for testing! Unfortunately, I'm not going to be able to investigate as I'm on vacation with limited access to computers until August. I wonder if the API changed between beta and release leading to that exception, as it did not occur for me while testing (I have a similar set of test playbooks). I'd also be curious if we tested with different versions of boto3 (this PR could potentially be a culprit : boto/botocore@36df38d) I'd greatly appreciate if you could help me look in to it. Completely understand if you cannot, but expect no progress on this PR from me for about a month. |
The issue is that you're calling 'create_mount_target()' without checking the state being available first.
I'm assuming you've set wait to True in your test cases? I can think of a number of fixes, but not currently got time to try them out. |
@jonhadfield - thanks for the debugging help! You were spot-on with To answer your question:
No. I don't think the added complexity of a wait here is worthwhile. I've removed it and updated the PR. Let me know if things are working for you now. Thanks! |
Creation now working, but deletion is only working by id and not name. |
@jonhadfield - I am not able to reproduce. Deletion with wait:yes and wait:no using both ID and name are working for me. Can you show me what you're doing that is failing? Code snippets:
|
@gregdek - is there anything else I can do to push this along outside of wait for community members to test and sign off? |
Works for me - 🚢 ship_it 🚢 |
description: | ||
- Allows to create, search and destroy Amazon EFS file system | ||
required: true | ||
choices: ['present', 'absent', 'list'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think list
would be better off as its own facts
module, not a "state" on this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
@ryansydnor A friendly reminder: this pull request has been marked as needing your action. If you still believe that this PR applies, and you intend to address the issues with this PR, just let us know in the PR itself and we will keep it open pending your changes. When you do address the issues, please respond with ready_for_review in your comment, so that we can notify the maintainer. [This message brought to you by your friendly Ansibull-bot.] |
@gregdek - addressed the comments from ryansb. split the "list" functionality into its own module (included in this PR for testing purposes). |
Can state please be optional and default to present as with other modules ? And can you add the performanceMode parameter too ? |
|
||
DOCUMENTATION = ''' | ||
--- | ||
module: efs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
efs_facts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks for pointing that out.
Use snake_case instead of CamelCase Remove unused code Update docs Make python 2.6 compatible Add performanceMode parameter
@fvant - state is now optional (default to present). added performance mode as a parameter. thanks again for taking a look! |
shipit |
LGTM |
@paprins: The ansibots doesn't understand LGTM. ;) shipit |
Thanks again to @ryansydnor for this PR, and thanks @ansible/core for reviewing. Marking for inclusion. [This message brought to you by your friendly Ansibull-bot.] |
|
||
def __init__(self, module, region, **aws_connect_params): | ||
try: | ||
session = Session( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to be using boto3_conn from EC2 module_utils, this connection method doesn't work for users that have multiple AWS profiles set up.
file_systems_info = connection.get_file_systems(FileSystemId=fs_id, CreationToken=name) | ||
|
||
if tags: | ||
file_systems_info = filter(lambda item: has_tags(item['Tags'], tags), file_systems_info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd really prefer [item for item in file_systems_info if has_tags(item['Tags'], tags)]
here. Filter with lambdas is a bit clunky.
if targets: | ||
targets = [(item, prefix_to_attr(item)) for item in targets] | ||
file_systems_info = filter(lambda item: | ||
has_targets(item['MountTargets'], targets), file_systems_info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here - list comprehension would be cleaner.
has_targets(item['MountTargets'], targets), file_systems_info) | ||
|
||
file_systems_info = [camel_dict_to_snake_dict(x) for x in file_systems_info] | ||
module.exit_json(changed=False, efs=file_systems_info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For facts modules we encourage returning your info as part of ansible_facts
so users don't have to register your output, for example:
module.exit_json(changed=False, ansible_facts={'efs': file_systems_info})
That way usage could look like:
- efs_facts:
profile: my-aws-account
- command: "echo my EFS has {{ efs.number_of_mount_targets }} targets associated"
CreationToken=name, | ||
FileSystemId=file_system_id | ||
)) | ||
return info and info['LifeCycleState'] or self.STATE_DELETED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid this boolean you can instead use info.get('LifeCycleState', self.STATE_DELETED)
'security_groups': 'SecurityGroups', | ||
'subnet_id': 'SubnetId' | ||
} | ||
targets = [dict((target_translations[key], value) for (key, value) in x.items()) for x in module.params.get('targets')] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add comments to explain what's going on here and what data goes in/out of this?
|
||
def __init__(self, module, region, **aws_connect_params): | ||
try: | ||
session = Session( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same boto3_conn connection comment as below. Just replace with:
try:
- session = Session(
- aws_access_key_id=aws_connect_params['aws_access_key_id'],
- aws_secret_access_key=aws_connect_params['aws_secret_access_key'],
- aws_session_token=aws_connect_params['aws_session_token'],
- region_name=region
- )
- self.connection = session.client('efs')
+ self.connection = boto3_conn(module, conn_type='client',
+ resource='efs', region=region,
+ **aws_connect_params)
except Exception as e:
- module.fail_json(msg=repr(e))
+ module.fail_json(msg="Failed to connect to AWS " + str(e), exception=traceback.format_exc(e))
Going to go ahead with shipping this, but I'd really appreciate if you could follow up on these changes in another PR |
Nice work @ryansydnor. Thanks. |
@ryansydnor @ryansb state should also be explicit not optional - core team request from a while back. Also, there isn't a single try catch block around any of the boto3 calls.... :( |
@wimnat I see #2305 (comment). Where's the core team request from awhile ago? |
@tima i had a look around and couldn't find it. It'll be either in the google devel group or a comment on a PR somewhere! Pretty much untraceable but i didn't imagine it :) I'll do a PR to update the docs |
Did a follow up PR get raised, I don't see a link here |
ISSUE TYPE
COMPONENT NAME
efs (elastic file system)
efs_facts (elastic file system facts)
ANSIBLE VERSION
Tested against: ansible 2.1.1.0
SUMMARY
Adds the ability to create, manage, and delete elastic file systems