Help - generating a table of task results in ansible

Hello devs,

First time posting here, apologies if not the done thing or the wrong place to post.

I’m not looking for a fix to an issue I’ve run into, rather I’m interested to know whether a strategy I’m thinking about sounds feasible or not, and whether there’s any recommendations on better approaches… let’s say I’m on a fact finding mission.

Current state
I run some drift detection/correction & smoke tests from a scheduled ansible play, this play might include up to 20 tasks which get invoked by a main.yml. The schedule is run every hour against a few k8s clusters/endpoints/nodes by awx which posts a message via a slack webhook to tell me if the job ran or failed and posts some output too. The trouble is, I often have to look in awx or read some output, to tell me what happened when something went wrong.

That can take the form of stdout_lines, ansible output etc but always results in me having to look at some output.

Project Layout

.
├── CHANGELOG.md
├── README.md
├── ansible.cfg
├── inventory
│ ├── dev.all.aws_ec2.yaml
│ ├── staging.all.aws_ec2.yaml
│ └── prod.all.aws_ec2.yaml
├── playbooks
| ├── drift.yaml
│ └── smoke_tests.yaml
└── tasks
├── main.yaml
├── check_cluster_health_api.yaml
├── check_active_passive_cluster.yaml
├── check_dns.yaml
├── check_http_statuses.yaml
├── check_internet_connectivity.yaml
├── check_tcp_ports.yaml
├── check_kube_system_pods.yaml
├── check_etcd_cluster_health.yaml

Desired state
These tests already assert success or failure and if the job fails, I know some task failed. I’d like to capture the result of each task (say, 0 for success, 1 for fail), template something like an html table or ASCII table and then send that to slack instead.

What main looks like

Don't make the code more complex. Use ansible-runner to run the
projects and analyse the potential problems from outside
https://ansible-runner.readthedocs.io/en/latest/

ansible-runner artifacts will provide you with all the details
https://ansible-runner.readthedocs.io/en/latest/intro.html#runner-artifacts-directory-hierarchy
See for example
https://gist.github.com/vbotka/31ccd5380a2b230be11b1df78cc402a1

FWIW. See the example of a script how to run projects via
ansible-runner and create simple log of what succeeded and failed
https://github.com/vbotka/ansible-runner/blob/master/contrib/ansible-cron-audit.bash
https://github.com/vbotka/ansible-runner/blob/master/contrib/arwrapper.bash

The idea is to run the script from cron and receive an email on
failures only. The log can be scanned manually or sent to an external
logging. If a playbook fails go to the ansible-runner artifacts and
find the details. Next step might be the automation of the artifacts'
analysis.

See "Ansible Runner Usage Examples"
https://ansible-runner-role.readthedocs.io/en/latest/guide.html#ansible-runner-usage-examples