[Feature Request] Warn user if nothing is matched by tag

11 views
Skip to first unread message

Matthew Davis

unread,
May 15, 2019, 7:58:51 PM5/15/19
to Ansible Project
Following on from this github issue.

If the user mis-spells a tag when invoking a playbook, then Ansible will run 0 tasks and claim it succeeded. This is misleading.


Ansible should warn users when 0 tasks match the tags, because the user probably did not intent to run 0 tasks.


e.g.


---
- hosts: localhost
 
tasks:
     
- name: test
       
debug:
         
msg: "test"
       
tags:
         
- something

Invoke it with


ansible-playbook test.yaml --tags somethin

(Note the lack of the e at the end. It's a mis-spelled tag.)


Expected behavior: Ansible warns the user that no tag called somethin exists, and zero tasks will be run.


Actual behavior: Ansible runs and prints all green, but for zero tasks. As a user my first impression was that all tasked tagged with something had been completed, but this was not the case.


The answer I got on github was that it is not possible to count the number of matched tasks prior to execution. However what about after execution?


i.e. make `ansible-playbook --tags blah playbook.yaml` do this:


num_tasks_run = 0
for task in tasks:
   
if tag in task:
        task
.do()
    num_tasks_run
+= 1

if (num_tasks_run == 0):
   
print("Warning: No tasks were run. Did you misspell your tag?")

Can someone tell me whether this method is feasible?

I'm not familiar with the code base. I'm happy to write it if someone points me in the right direction.


(Looking at the repo, it's not clear where anything is. E.g. there's a bin directory, even though Ansible can be run without compiling to a binary.)



Regards,

Matt



Reply all
Reply to author
Forward
0 new messages