<commit_before>---
- hosts: localhost
  gather_facts: no
  vars:
    deleteme_name: 'terry'
    deleteme_rules: >
        path "secret/{{deleteme_name}}/*" {
          capabilities = ["create", "read", "update", "delete", "list"]
        } 
        path "secret/{{deleteme_name}}" {
          capabilities = ["list"]
        } 
  tasks:
    - name: "Create a policy"
      hashivault_policy_set:
        name: "{{deleteme_name}}"
        rules: "{{deleteme_rules}}"
        token: "{{ vault_root_token }}"
      register: 'vault_policy_set'
    - assert:
        that:
          - "{{vault_policy_set.changed}} == True"
          - "{{vault_policy_set.rc}} == 0"

    - name: "Get '{{deleteme_name}}' policy"
      hashivault_policy_get:
        name: '{{deleteme_name}}'
        token: "{{ vault_root_token }}"
      register: 'vault_policy_get'
    - assert:
        that:
          - "{{vault_policy_get.changed}} == False"
          - "'{{vault_policy_get.rules}}' == '{{deleteme_rules}}'"
          - "{{vault_policy_get.rc}} == 0"

    - name: "List the policies, check if '{{deleteme_name}}' policy is listed"
      hashivault_policy_list:
        token: "{{ vault_root_token }}"
      register: 'vault_policy_list'
    - assert:
        that:
          - "{{vault_policy_list.changed}} == False"
          - "{{vault_policy_list.rc}} == 0"
    - fail:
        msg: "policy {{deleteme_name}} not in list"
      when: deleteme_name not in vault_policy_list.policies

    - name: "Delete '{{deleteme_name}}' policy"
      hashivault_policy_delete:
        name: '{{deleteme_name}}'
        token: "{{ vault_root_token }}"
      register: 'vault_policy_delete'
    - assert:
        that:
          - "{{vault_policy_delete.changed}} == True"
          - "{{vault_policy_delete.rc}} == 0"

    - name: "List the policies, check that '{{deleteme_name}}' is no longer listed"
      hashivault_policy_list:
        token: "{{ vault_root_token }}"
      register: 'vault_policy_list'
    - assert:
        that:
          - "{{vault_policy_list.changed}} == False"
          - "{{vault_policy_list.rc}} == 0"
    - fail:
        msg: "policy {{deleteme_name}} in list"
      when: deleteme_name in vault_policy_list.policies<commit_msg>Just refactoring. No more using fail. I negated the logic in their check and added it as an assert condition.<commit_after>---
- hosts: localhost
  gather_facts: no
  vars:
    name: 'terry'
    rules: >
        path "secret/{{name}}/*" {
          capabilities = ["create", "read", "update", "delete", "list"]
        } 
        path "secret/{{name}}" {
          capabilities = ["list"]
        }

  tasks:
    - name: "Create a policy (that we're going to delete at the end)"
      hashivault_policy_set:
        name: "{{name}}"
        rules: "{{rules}}"
        token: "{{vault_root_token}}"
      register: 'vault_policy_set'
    - assert:
        that:
          - "{{vault_policy_set.changed}} == True"
          - "{{vault_policy_set.rc}} == 0"

    - name: "Get '{{name}}' policy"
      hashivault_policy_get:
        name: '{{name}}'
        token: "{{ vault_root_token }}"
      register: 'vault_policy_get'
    - assert:
        that:
          - "{{vault_policy_get.changed}} == False"
          - "'{{vault_policy_get.rules}}' == '{{rules}}'"
          - "{{vault_policy_get.rc}} == 0"

    - name: "List the policies, check if '{{name}}' policy is listed"
      hashivault_policy_list:
        token: "{{ vault_root_token }}"
      register: 'vault_policy_list'

    - assert:
        that:
          - "{{vault_policy_list.changed}} == False"
          - "{{vault_policy_list.rc}} == 0"
          - "{{name in vault_policy_list['policies']}}"

    - name: "Delete '{{name}}' policy"
      hashivault_policy_delete:
        name: '{{name}}'
        token: "{{ vault_root_token }}"
      register: 'vault_policy_delete'
    - assert:
        that:
          - "{{vault_policy_delete.changed}} == True"
          - "{{vault_policy_delete.rc}} == 0"

    - name: "List the policies, check that '{{name}}' is no longer listed"
      hashivault_policy_list:
        token: "{{ vault_root_token }}"
      register: 'vault_policy_list'

    - assert:
        that:
          - "{{vault_policy_list.changed}} == False"
          - "{{vault_policy_list.rc}} == 0"
          - "{{name not in vault_policy_list['policies']}}"
{'fraction_non_alphanumeric': 0.15800320586214792, 'fraction_numerical': 0.002289901534234028, 'mean_word_length': 2.2842105263157895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4008233', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1448, 'n_words': 295}