@@ -0,0 +1,1924 @@
+#!/usr/bin/env python%0A# -*- coding: utf-8 -*-%0A%0Afrom __future__ import print_function%0Afrom ansible.module_utils.basic import *%0A%0ADOCUMENTATION = '''%0A---%0Amodule: container_file_content%0Aauthor: Edoardo Putti%0Ashort_description: Return the content of a file%0Adescription:%0A    - Retrieve the content for the given path on the given container%0Aoptions:%0A    name:%0A        required: true%0A        description:%0A            - Name of the container%0A    path:%0A        required: true%0A        description:%0A            - path of the file to check%0A'''%0A%0Adef read_file_in_container(path):%0A    import json%0A    with open(path, 'r') as lines:%0A        print(json.dump(%7B key_data: lines.read()%7D))%0A    return 0%0A%0Adef main():%0A    module = AnsibleModule(%0A            argument_spec = dict(%0A                name = dict(%0A                    required = True,%0A                    type = 'str',%0A                    ),%0A                path = dict(%0A                    required = True,%0A                    type = 'str',%0A                    ),%0A            ),%0A    )%0A%0A    try:%0A        import lxc%0A%0A    except ImportError:%0A        module.fail_json(%0A                changed = False,%0A                failed = True,%0A                msg = 'Error importing lxc, is python-lxc installed?',%0A                )%0A%0A    container_name = module.params.get('name')%0A    file_path = module.params.get('path')%0A%0A    result = %7B%7D%0A    result%5B'name'%5D = container_name%0A    result%5B'path'%5D = file_path%0A%0A    if container_name in lxc.list_containers():%0A%0A        container = lxc.Container(container_name)%0A%0A        file_exists = container.attach_wait(%0A                read_file_in_container,%0A                file_path,%0A                env_policy = lxc.LXC_ATTACH_CLEAR_ENV,%0A                )%0A%0A    else:%0A        result%5B'changed'%5D = False%0A        result%5B'failed'%5D = True%0A        result%5B'msg'%5D = %22Target container does not exists%22%0A%0A    module.exit_json(**result)%0A%0Aif __name__ == '__main__':%0A    main()%0A

add draft for reading file in container from ansible