<commit_before>---

- name: Fetch the certificate bundle and store it as a variable for use
  uri:
    url: "{{ papertrail_rsyslog_tls_cert_bundle_url }}"
    return_content: yes
  delegate_to: 127.0.0.1
  run_once: true
  register: papertrail_rsyslog_tls_cert_bundle_result
  when: papertrail_rsyslog_tls_cert_bundle is not defined

- name: Set as a variable to use for this server
  set_fact:
    papertrail_rsyslog_tls_cert_bundle: "{{ papertrail_rsyslog_tls_cert_bundle_result.content }}"
  when: papertrail_rsyslog_tls_cert_bundle is not defined

- name: Copy the bundle into position
  template:
    src:    "{{ papertrailapp_rsyslog_tls_cert_bundle_template }}"
    dest:   "{{ papertrail_rsyslog_tls_cert_bundle_path }}"
    mode:   "{{ papertrail_rsyslog_tls_cert_bundle_mode }}"
    owner:  "{{ papertrail_rsyslog_tls_cert_bundle_owner }}"
    group:  "{{ papertrail_rsyslog_tls_cert_bundle_group  }}"
  when: papertrail_rsyslog_tls_cert_bundle is defined

- name: Stat the certificate
  stat:
    get_checksum: yes
    get_md5: yes
    path: "{{ papertrail_rsyslog_tls_cert_bundle_path }}"
  register: papertrail_rsyslog_tls_cert_bundle_stat
  when: papertrail_rsyslog_tls_cert_bundle_checksum is defined

- name: Check the checksum against the stat
  fail:
    msg: "Checksum for certificate {{ papertrail_rsyslog_tls_cert_bundle_path }} do not match"
  when: papertrail_rsyslog_tls_cert_bundle_checksum is defined and papertrail_rsyslog_tls_cert_bundle_stat.stat.md5 != papertrail_rsyslog_tls_cert_bundle_checksum



...<commit_msg>Add check to variable before we send as validation<commit_after>---

- name: Fetch the certificate bundle and store it as a variable for use
  uri:
    url: "{{ papertrail_rsyslog_tls_cert_bundle_url }}"
    return_content: yes
  delegate_to: 127.0.0.1
  run_once: true
  register: papertrail_rsyslog_tls_cert_bundle_result
  when: papertrail_rsyslog_tls_cert_bundle is not defined

- name: Set as a variable to use for this server
  set_fact:
    papertrail_rsyslog_tls_cert_bundle: "{{ papertrail_rsyslog_tls_cert_bundle_result.content }}"
  when: papertrail_rsyslog_tls_cert_bundle is not defined

- name: Compare the bundle variable now to the checksum to save copying to the server
  fail:
    msg: "The certificate bundle does not match the expected checksum {{ papertrail_rsyslog_tls_cert_bundle_checksum }}"
  when: |
    papertrail_rsyslog_tls_cert_bundle_checksum is defined
    and {{ papertrail_rsyslog_tls_cert_bundle | hash('md5') }} != papertrail_rsyslog_tls_cert_bundle_checksum"

- name: Copy the bundle into position
  template:
    src:    "{{ papertrailapp_rsyslog_tls_cert_bundle_template }}"
    dest:   "{{ papertrail_rsyslog_tls_cert_bundle_path }}"
    mode:   "{{ papertrail_rsyslog_tls_cert_bundle_mode }}"
    owner:  "{{ papertrail_rsyslog_tls_cert_bundle_owner }}"
    group:  "{{ papertrail_rsyslog_tls_cert_bundle_group  }}"
  when: papertrail_rsyslog_tls_cert_bundle is defined

- name: Stat the certificate
  stat:
    get_checksum: yes
    get_md5: yes
    path: "{{ papertrail_rsyslog_tls_cert_bundle_path }}"
  register: papertrail_rsyslog_tls_cert_bundle_stat
  when: papertrail_rsyslog_tls_cert_bundle_checksum is defined

- name: Check the checksum against the stat
  fail:
    msg: "Checksum for certificate {{ papertrail_rsyslog_tls_cert_bundle_path }} do not match"
  when: |
    papertrail_rsyslog_tls_cert_bundle_checksum is defined
    and papertrail_rsyslog_tls_cert_bundle_stat.stat.md5 != papertrail_rsyslog_tls_cert_bundle_checksum

...
{'fraction_non_alphanumeric': 0.06768620787312377, 'fraction_numerical': 0.004814500141602946, 'mean_word_length': 5.251327433628319, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2810941', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1246, 'n_words': 261}