<commit_before>---
- name: Check whether Application Server is registered as OSSEC agent.
  command: /var/ossec/bin/list_agents -a
  register: ossec_list_agents_result
  # Read-only task, so don't report changed
  when: ossec_is_server
  changed_when: false

# Gnarly vars retrieval logic in this task. The "register" action above applies
# only to the Monitor Server, so the Application Server won't be able to access
# the value (and the play will fail as a result). So on both hosts, let's look up
# the registered value by referencing the hostvars for the Monitor Server, then
# copy the result to a more conveniently named fact on both hosts.
- name: Set host fact for OSSEC registration state.
  set_fact:
    ossec_agent_already_registered: "{{ app_ip+' is available.' in hostvars[groups.securedrop_monitor_server.0].ossec_list_agents_result.stdout }}"
  # No "delegate_to", so that *both* hosts are aware of registration stauts via set_fact.

- name: Find existing ossec remote IDs
  find:
    paths: /var/ossec/queue/rids
    patterns: '^\d+$'
    use_regex: "yes"
  when:
    - ossec_is_server
  register: _existing_rids

- name: Build list of existing remote IDs
  set_fact:
    build_rids: "{{ build_rids|default([]) + [item.path|basename] }}"
  with_items: "{{ _existing_rids.files }}"
  when:<commit_msg>Clean-up systems with multiple agents<commit_after>---
- name: Check whether Application Server is registered as OSSEC agent.
  command: /var/ossec/bin/list_agents -a
  register: ossec_list_agents_result
  # Read-only task, so don't report changed
  when: ossec_is_server
  changed_when: false

# Gnarly vars retrieval logic in this task. The "register" action above applies
# only to the Monitor Server, so the Application Server won't be able to access
# the value (and the play will fail as a result). So on both hosts, let's look up
# the registered value by referencing the hostvars for the Monitor Server, then
# copy the result to a more conveniently named fact on both hosts.
- name: Set host fact for OSSEC registration state.
  set_fact:
    ossec_agent_already_registered: "{{ app_ip+' is available.' in hostvars[groups.securedrop_monitor_server.0].ossec_list_agents_result.stdout }}"
  # No "delegate_to", so that *both* hosts are aware of registration stauts via set_fact.

- name: Find existing ossec remote IDs
  find:
    paths: /var/ossec/queue/rids
    patterns: '^\d+$'
    use_regex: "yes"
  when:
    - ossec_is_server
  register: _existing_rids

- name: Overload agent already registered status to force reinstall
  set_fact:
    ossec_agent_already_registered: false
  when: hostvars[groups.securedrop_monitor_server.0]._existing_rids.matched > 1

- name: Build list of existing remote IDs
  set_fact:
    build_rids: "{{ build_rids|default([]) + [item.path|basename] }}"
  with_items: "{{ _existing_rids.files }}"
  when:
{'fraction_non_alphanumeric': 0.08627314006287111, 'fraction_numerical': 0.0013971358714634998, 'mean_word_length': 4.235831809872029, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '4261392', 'n_tokens_mistral': 907, 'n_tokens_neox': 874, 'n_words': 322}