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*

---

- name: Cluster Health API
import_tasks: check_cluster_health_api.yaml
tags: oc_health

- name: Check A/P cluster
import_tasks: check_active_passive_cluster.yaml
tags: ap_cluster

- name: Check DNS
import_tasks: check_dns.yaml
tags: dnsmasq

etc...

*Some ideas*

   - Set a fact to an empty dict in main, run each task from main, insert 
   some data into dict. Template it at the end, send to slack. Bit of code 
   smell, lots of dupe statements. Not sure whether this is possible, to have 
   a global var, not defined in  each task individually.


   - Use a handler? Not totally sure how this would work, but the thinking 
   is to register some facts per task and have a subsequent task notify the 
   handler to *do something (append to dict for e.g.). *Template at the 
   end. As above not sure how var precedence would behave here, but I like the 
   idea of treating a handler like a "module" and passing it some input, 
   getting some output.


   - Move all of my tests into a single task, or play as it'll be trivial 
   to create and append to an obj in a single task. Don't want to do this 
   really unless absolutely necessary.


Have looked through some other posts in the google group, the most relevant 
one I found was this 
<https://groups.google.com/g/ansible-project/c/hBo1UbAHip8>. This it's a 
pretty simple example.

Interested to know if people with more experience have seen a requirement 
like this, if any of the above thoughts seem viable or even if people think 
this is a bad idea.

Anyway - all suggestions welcome!

Have a good one wherever you are.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b63c783d-91cc-4cd3-aa4b-45912eb2fd7fn%40googlegroups.com.

Reply via email to