def read_int(module, file_path):
    """Read a file and convert its value to int.

    Raise ansible failure otherwise.
    """
    try:
        with open(file_path) as f:
            file_contents = f.read()
        return int(file_contents)
    except IOError:
        module.fail_json(msg="Cannot open '%s'" % file_path)
    except ValueError:
        module.fail_json(msg=
            "The '%s' file doesn't contain an integer value" % file_path)
