Following on from this github issue 
<https://github.com/ansible/ansible/issues/56106>.

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



-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/0927ff97-f648-4abe-a923-c07cbdd157bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to