Created
July 28, 2014 14:46
-
-
Save gbirke/4dfaaf5c6a575d4661cf to your computer and use it in GitHub Desktop.
Ansible module for linking to vendor directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from ansible.module_utils.basic import * | |
import os.path | |
import json | |
def main(): | |
module = AnsibleModule( | |
argument_spec = dict( | |
dest=dict(required=True), | |
lockfile=dict(default="composer.lock"), | |
vendor=dict(default="vendor"), | |
) | |
) | |
dest = module.params['dest'] | |
lockfile = module.params['lockfile'] | |
vendor = module.params['vendor'] | |
if not os.path.isdir(dest): | |
module.fail_json(msg="Destination path '%s' does not exist." % dest) | |
try: | |
lockfile_handle = open(lockfile) | |
data = json.load(lockfile_handle) | |
lockfile_handle.close() | |
except IOError: | |
module.fail_json(msg="lockfile '%s' cannot be opened." % lockfile) | |
if not "hash" in data: | |
module.fail_json(msg="No hash was found in %s" % lockfile) | |
# TODO | |
# if vendor exists and is not a symlink to hash, exit (nothing changed) | |
# if dest+hash exists, symlink vendor to dest+hash | |
# if dest+hash does not exist, create dest+hash, symlink vendor to dest+hash, | |
# | |
module.exit_json(changed=False, hash=data["hash"]) | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment