Ensure a Vault policy with the given name and rules is present.

    name
        The name of the policy

    rules
        Rules formatted as in-line HCL


    .. code-block:: yaml

        demo-policy:
          vault.policy_present:
            - name: foo/bar
            - rules: |
                path "secret/top-secret/*" {
                  policy = "deny"
                }
                path "secret/not-very-secret/*" {
                  policy = "write"
                }

def policy_present(name, rules):
    '''
    Ensure a Vault policy with the given name and rules is present.

    name
        The name of the policy

    rules
        Rules formatted as in-line HCL


    .. code-block:: yaml

        demo-policy:
          vault.policy_present:
            - name: foo/bar
            - rules: |
                path "secret/top-secret/*" {
                  policy = "deny"
                }
                path "secret/not-very-secret/*" {
                  policy = "write"
                }

    '''
    url = "v1/sys/policy/{0}".format(name)
    response = __utils__['vault.make_request']('GET', url)
    try:
        if response.status_code == 200:
            return _handle_existing_policy(name, rules, response.json()['rules'])
        elif response.status_code == 404:
            return _create_new_policy(name, rules)
        else:
            response.raise_for_status()
    except Exception as e:
        return {
            'name': name,
            'changes': {},
            'result': False,
            'comment': 'Failed to get policy: {0}'.format(e)
        }