diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 3da9bf4..182258c 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -28,6 +28,6 @@ jobs: ansible-lint --version - name: Test run: | - cd roles/vector && molecule test + cd roles/vector && molecule test --all diff --git a/roles/vector/molecule/features/converge.yml b/roles/vector/molecule/features/converge.yml new file mode 100644 index 0000000..f1926d7 --- /dev/null +++ b/roles/vector/molecule/features/converge.yml @@ -0,0 +1,33 @@ +--- +- name: Converge + hosts: all + tasks: + - name: "Include vector" + include_role: + name: "vector" + vars: + vector_template: vector.yaml.j2 + vector_config_file: /etc/vector/vector.yaml + sources: + journald: + type: journald + current_boot_only: true + tcp: + type: socket + mode: tcp + address: 0.0.0.0:6000 + encoding: + codec: json + transforms: + grok: + type: grok_parser + inputs: + - journald + pattern: '(?\\d+)%{GREEDYDATA}' + sinks: + console: + type: console + encoding: + codec: json + inputs: + - grok diff --git a/roles/vector/molecule/features/molecule.yml b/roles/vector/molecule/features/molecule.yml new file mode 100644 index 0000000..14d5079 --- /dev/null +++ b/roles/vector/molecule/features/molecule.yml @@ -0,0 +1,33 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: | + set -e + yamllint . + ansible-lint + flake8 +platforms: + - name: debian10 + image: jrei/systemd-debian:10 + privileged: true + command: /lib/systemd/systemd + tmpfs: + - /run + - /tmp + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + - name: rocky8 + image: rockylinux:8 + privileged: true + command: /usr/sbin/init + tmpfs: + - /run + - /tmp + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro +provisioner: + name: ansible +verifier: + name: ansible diff --git a/roles/vector/molecule/features/verify.yml b/roles/vector/molecule/features/verify.yml new file mode 100644 index 0000000..8b8fffe --- /dev/null +++ b/roles/vector/molecule/features/verify.yml @@ -0,0 +1,33 @@ +--- +- name: Verify + hosts: all + gather_facts: true + tasks: + - name: Install netstat + yum: + name: + - net-tools + - procps + state: present + when: ansible_os_family == 'RedHat' + - name: Install netstat + apt: + name: + - net-tools + - procps + state: present + update_cache: yes + when: ansible_os_family == 'Debian' + - name: Execute vector + command: vector --version + changed_when: false + register: vector_version_rc + - name: Check port 6000 is open + community.general.listen_ports_facts: + - name: Assert vector is installed + assert: + that: + - vector_version_rc is success + - 6000 in open_ports + vars: + open_ports: "{{ ansible_facts.tcp_listen | map(attribute='port') }}" diff --git a/roles/vector/tasks/main.yml b/roles/vector/tasks/main.yml index 8eb0594..3c2d233 100644 --- a/roles/vector/tasks/main.yml +++ b/roles/vector/tasks/main.yml @@ -42,6 +42,12 @@ mode: 0644 notify: restart vector +- name: Use the right config_file + lineinfile: + path: /etc/default/vector + line: "VECTOR_CONFIG={{ vector_config_file }}" + state: present + - name: Add vector user to docker group user: name: vector diff --git a/roles/vector/templates/vector.yaml.j2 b/roles/vector/templates/vector.yaml.j2 new file mode 100644 index 0000000..6da1ff3 --- /dev/null +++ b/roles/vector/templates/vector.yaml.j2 @@ -0,0 +1,7 @@ +{{ vector_general_config | default("") }} +sources: + {{ sources | to_nice_yaml | indent(2) }} +transforms: + {{ transforms | to_nice_yaml | indent(2) }} +sinks: + {{ sinks | to_nice_yaml | indent(2) }}