- block:

  - name: Ensure Filebeat SSL key pair directory exists.
    file:
      path: "{{ filebeat_ssl_dir }}"
      state: directory
      owner: root
      group: root
      mode: 500

  - name: Copy the certificates from local to the Manager instance
    copy:
      src: "{{ local_certs_path }}/wazuh-certificates/{{ item }}"
      dest: "{{ filebeat_ssl_dir }}"
      owner: root
      group: root
      mode: 400
    with_items:
      - "{{ filebeat_node_name }}-key.pem"
      - "{{ filebeat_node_name }}.pem"
      - "root-ca.pem"

  tags:
  - security
  when:
  - filebeat_security
