Change parameter to type=path

Read as binary for python3 preparedness
This commit is contained in:
Toshio Kuratomi 2016-02-29 00:38:10 -08:00 committed by Matt Clay
parent 390dbe5090
commit 0400efa3f8

View file

@ -55,23 +55,24 @@ import base64
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec = dict( argument_spec = dict(
src = dict(required=True, aliases=['path']), src = dict(required=True, aliases=['path'], type='path'),
), ),
supports_check_mode=True supports_check_mode=True
) )
source = os.path.expanduser(module.params['src']) source = module.params['src']
if not os.path.exists(source): if not os.path.exists(source):
module.fail_json(msg="file not found: %s" % source) module.fail_json(msg="file not found: %s" % source)
if not os.access(source, os.R_OK): if not os.access(source, os.R_OK):
module.fail_json(msg="file is not readable: %s" % source) module.fail_json(msg="file is not readable: %s" % source)
data = base64.b64encode(file(source).read()) data = base64.b64encode(open(source, 'rb').read())
module.exit_json(content=data, source=source, encoding='base64') module.exit_json(content=data, source=source, encoding='base64')
# import module snippets # import module snippets
from ansible.module_utils.basic import * from ansible.module_utils.basic import *
main() if __name__ == '__main__':
main()