96 lines
3.0 KiB
YAML
96 lines
3.0 KiB
YAML
---
|
|
# vars are defined molecule.yml to avoid repeading them for each play
|
|
- name: Create collection dir play
|
|
hosts: localhost
|
|
tasks:
|
|
|
|
- name: Create temp collection folder
|
|
file:
|
|
path: "{{ local_working_dir }}"
|
|
state: directory
|
|
mode: 0755
|
|
|
|
# Assure we do not have leftovers from previous runs there, not needed in production.
|
|
- name: Remove collected_files folder
|
|
file:
|
|
path: "{{ local_working_dir }}/collected_files"
|
|
state: absent
|
|
|
|
- name: "Converge collect play"
|
|
hosts: all
|
|
strategy: free
|
|
vars:
|
|
expected:
|
|
- 'cmd': 'cat /proc/cpuinfo'
|
|
'capture_file': '/var/log/extra/cpuinfo.txt'
|
|
'name': 'cpuinfo'
|
|
'group': 'system'
|
|
- 'cmd': 'cat /proc/meminfo'
|
|
'capture_file': '/var/log/extra/meminfo.txt'
|
|
'name': 'meminfo'
|
|
'group': 'system'
|
|
- 'cmd': 'cat /proc/swaps'
|
|
'capture_file': '/var/log/extra/swaps.txt'
|
|
'name': 'swaps'
|
|
'group': 'system'
|
|
tasks:
|
|
|
|
# brief call used a very short override artcl_commands, enough to validate
|
|
# that the combining of the commands works. Later we import the role with
|
|
# its default artcl_commands in order to test these commands, too.
|
|
- name: "Include collect_logs :: collect (brief)"
|
|
vars:
|
|
artcl_collect: true
|
|
artcl_commands:
|
|
system:
|
|
cpuinfo:
|
|
cmd: cat /proc/cpuinfo
|
|
capture_file: /var/log/extra/cpuinfo.txt
|
|
meminfo:
|
|
cmd: cat /proc/meminfo
|
|
capture_file: /var/log/extra/meminfo.txt
|
|
swaps:
|
|
cmd: cat /proc/swaps
|
|
capture_file: /var/log/extra/swaps.txt
|
|
include_role:
|
|
name: collect_logs
|
|
|
|
- name: Verify expected combined commands
|
|
assert:
|
|
that: artcl_commands_flatten['data'] == expected
|
|
fail_msg: |
|
|
artcl_commands_flatten had unexpected value {{ artcl_commands_flatten }}
|
|
success_msg: artcl_commands_flatten had correct value
|
|
|
|
- name: Verify that expected files where collected and they are not empty
|
|
delegate_to: localhost
|
|
stat:
|
|
path: "{{ local_working_dir }}/collected_files/{{ inventory_hostname }}{{ item.capture_file }}"
|
|
register: st
|
|
failed_when: not st.stat.exists or st.stat.size == 0
|
|
loop: "{{ expected }}"
|
|
|
|
- name: "Include ansible-role-collect-logs :: collect (full)"
|
|
vars:
|
|
artcl_collect: true
|
|
include_role:
|
|
name: collect_logs
|
|
|
|
- name: "Converge publish play"
|
|
hosts: localhost
|
|
tasks:
|
|
- name: "Include ansible-role-collect-logs :: publish"
|
|
vars:
|
|
# disabling collect here is key for testing because collection needs
|
|
# sudo on targeted hosts, which is not available on molecule, zuul and
|
|
# some development environments.
|
|
artcl_collect: false
|
|
artcl_publish: true
|
|
include_role:
|
|
name: collect_logs
|
|
|
|
- name: Display stats
|
|
debug:
|
|
msg: |
|
|
Collected files should be under {{ local_working_dir }}/collected_files
|