<commit_before>---
# Really this is a check to see if we have to create the repo folder,
# if thats the case we are not under a local vagrant box with a synced
# root folder.
- name: Create src path folder
  file:
    state: directory
    path: "{{ item }}"
  with_items:
    - "{{ repo_src_path }}"
    - "{{ build_path }}"
  register: ossec_src_path_results

- name: Conditional copy over current directory for repo build
  synchronize:
    src: ../../../../
    dest: "{{ repo_src_path }}"
    use_ssh_args: yes
    recursive: yes
    rsync_opts:
      - "--exclude=*.git"
      - "--exclude=*.deb"
  when: ossec_src_path_results.changed

- name: Include OSSEC download URLs.
  ossec_urls:
    ossec_version: "{{ ossec_version }}"

- name: Download OSSEC tarball.
  get_url:
    url: "{{ ossec_tarball_url }}"
    dest: "{{ build_path }}/{{ ossec_tarball_filename }}"

- name: Gather checksum info for downloaded tarball.
  stat:
    path: "{{ build_path }}/{{ ossec_tarball_filename }}"
    get_md5: yes
  register: ossec_download

- name: Fail if MD5 and SHA1 checksums for tarball are not correct.
  fail:
    msg: >
      The checksums for {{ ossec_tarball_filename }} do not match.
      Both MD5 and SHA1 checksums were inspected. The checksums
      used for the inspection where:
        MD5: {{ ossec_md5_checksum }}
        SHA1: {{ ossec_sha1_checksum }}

      The checksums found were:
        MD5: {{ ossec_download.stat.md5 }}
        SHA1: {{ ossec_download.stat.checksum }}

      Try rerunning the playbook to download the files again.
  when: not (ossec_download.stat.exists and
             ossec_download.stat.md5 == "{{ ossec_md5_checksum }}" and
             ossec_download.stat.checksum == "{{ ossec_sha1_checksum }}")

- name: install deb packages required to build ossec package
  apt:
    name: "{{ item }}"
    state: present
    update_cache: yes
    cache_valid_time: 3600
  with_items: "{{ build_ossec_deb_pkg_dependencies }}"

- name: extract OSSEC archive to /tmp
  unarchive:
    copy: no
    src: "{{ build_path }}/{{ ossec_tarball_filename }}"
    dest: /tmp

- name: ensure ossec /etc dir exists
  file:
    state: directory
    dest: /tmp/ossec-hids-{{ ossec_version }}/etc

- name: copy ossec preloaded vars
  template:
    src: "{{ purpose }}-preloaded-vars.conf"
    dest: /tmp/ossec-hids-{{ ossec_version }}/etc/preloaded-vars.conf

- name: run ossec installer
  command: /tmp/ossec-hids-{{ ossec_version }}/install.sh

- name: create ossec agent deb build dir
  file:
    state: directory
    dest: /tmp/{{ ossec_build_dir }}

- name: ensure the temp ossec build dir var directory exists
  file:
    state: directory
    dest: /tmp/{{ ossec_build_dir }}/var

- name: mv /var/ossec to ossec build dir
  command: cp -R /var/ossec /tmp/{{ ossec_build_dir }}/var/

- name: copy OSSEC DEBIAN dir to build dir
  command: cp -R {{ repo_src_path }}/ossec-{{ purpose }}/DEBIAN /tmp/{{ ossec_build_dir }}

- name: template the control file
  template:
    src: "{{ purpose }}_control.j2"
    dest: /tmp/{{ ossec_build_dir }}/DEBIAN/control

- name: copy OSSEC usr dir to build dir
  command: cp -R {{ repo_src_path }}/ossec-{{ purpose }}/usr /tmp/{{ ossec_build_dir }}

- name: copy OSSEC etc dir to build dir
  command: cp -R {{ repo_src_path }}/ossec-{{ purpose }}/etc /tmp/{{ ossec_build_dir }}

- name: build securedrop ossec deb package
  command: dpkg-deb --build /tmp/{{ ossec_build_dir }}

- name: move securedrop ossec deb to repo<commit_msg>More readable task names throughout<commit_after>---
# Really this is a check to see if we have to create the repo folder,
# if thats the case we are not under a local vagrant box with a synced
# root folder.
- name: Create src path folder
  file:
    state: directory
    path: "{{ item }}"
  with_items:
    - "{{ repo_src_path }}"
    - "{{ build_path }}"
  register: ossec_src_path_results

- name: Conditional copy over current directory for repo build
  synchronize:
    src: ../../../../
    dest: "{{ repo_src_path }}"
    use_ssh_args: yes
    recursive: yes
    rsync_opts:
      - "--exclude=*.git"
      - "--exclude=*.deb"
  when: ossec_src_path_results.changed

- name: Include OSSEC download URLs.
  ossec_urls:
    ossec_version: "{{ ossec_version }}"

- name: Download OSSEC tarball.
  get_url:
    url: "{{ ossec_tarball_url }}"
    dest: "{{ build_path }}/{{ ossec_tarball_filename }}"

- name: Gather checksum info for downloaded tarball.
  stat:
    path: "{{ build_path }}/{{ ossec_tarball_filename }}"
    get_md5: yes
  register: ossec_download

- name: Fail if MD5 and SHA1 checksums for tarball are not correct.
  fail:
    msg: >
      The checksums for {{ ossec_tarball_filename }} do not match.
      Both MD5 and SHA1 checksums were inspected. The checksums
      used for the inspection where:
        MD5: {{ ossec_md5_checksum }}
        SHA1: {{ ossec_sha1_checksum }}

      The checksums found were:
        MD5: {{ ossec_download.stat.md5 }}
        SHA1: {{ ossec_download.stat.checksum }}

      Try rerunning the playbook to download the files again.
  when: not (ossec_download.stat.exists and
             ossec_download.stat.md5 == "{{ ossec_md5_checksum }}" and
             ossec_download.stat.checksum == "{{ ossec_sha1_checksum }}")

- name: Install apt dependencies for building OSSEC packages.
  apt:
    name: "{{ item }}"
    state: present
    update_cache: yes
    cache_valid_time: 3600
  with_items: "{{ build_ossec_deb_pkg_dependencies }}"

- name: Extract OSSEC source tarball.
  unarchive:
    copy: no
    src: "{{ build_path }}/{{ ossec_tarball_filename }}"
    dest: /tmp

- name: Create /etc directory within source directory.
  file:
    state: directory
    dest: /tmp/ossec-hids-{{ ossec_version }}/etc

- name: Copy OSSEC preloaded vars template.
  template:
    src: "{{ purpose }}-preloaded-vars.conf"
    dest: /tmp/ossec-hids-{{ ossec_version }}/etc/preloaded-vars.conf

- name: Run OSSEC installer script on extracted source.
  command: /tmp/ossec-hids-{{ ossec_version }}/install.sh

- name: Create OSSEC build directory.
  file:
    state: directory
    dest: "{{ item }}"
  with_items:
    - /tmp/{{ ossec_build_dir }}
    - /tmp/{{ ossec_build_dir }}/var

- name: Copy /var/ossec/ to OSSEC build directory.
  command: cp -R /var/ossec /tmp/{{ ossec_build_dir }}/var/

- name: Copy OSSEC DEBIAN package scripts to build directory.
  command: cp -R {{ repo_src_path }}/ossec-{{ purpose }}/DEBIAN /tmp/{{ ossec_build_dir }}

- name: Copy OSEC DEBIAN/control template to build directory.
  template:
    src: "{{ purpose }}_control.j2"
    dest: /tmp/{{ ossec_build_dir }}/DEBIAN/control

- name: Copy OSSEC /usr and /etc directories to build directory.
  command: cp -R {{ repo_src_path }}/ossec-{{ purpose }}/{{ item }} /tmp/{{ ossec_build_dir }}
  with_items:
    - etc
    - usr

- name: Build SecureDrop OSSEC deb package.
  command: dpkg-deb --build /tmp/{{ ossec_build_dir }}

- name: Move SecureDrop OSSEC deb package to repo to output directory.
{'fraction_non_alphanumeric': 0.12250427837992013, 'fraction_numerical': 0.005704506560182544, 'mean_word_length': 2.984659090909091, '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': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3426967', 'n_tokens_mistral': 2412, 'n_tokens_neox': 2368, 'n_words': 713}