Hello again,
wouldn’t be useful for a user to be able to run any available task that he has on a playbook, with /usr/bin/ansible?
I think that a feature like this would give great power to the end user for debugging purposes and not only. e.g. We (me and my team) have a use case that we need to run only 1 command to 100 hosts to update a service. We also believe that to make a playbook to run only 1 task is over-kill. We also have lots of templates that we want to watch them before we deploy them. Making a playbook, again, is too much for our needs.
I also believe that we can do that (make /usr/bin/ansible working as /usr/bin/ansible-playbook) without increasing the complexity of code and maintainability.
As I understand the needed variables would come from 4 different places:
- facts
- group_vars
- host_vars
- included files
/usr/bin/ansible would provide all those variables if we connect inventory class with steps 2,3,4 and if we give a flag (/usr/bin/ansible --gather-facts) for step 1.
I believe that a change like this would give great modularity to the code.
Right now, steps 2,3,4 are bound with play.py. By bounding steps 2,3,4 to inventory class, playbook class and ansible class could access host,group and file variables through methods like: inventory.get_group_vars(host) , inventory.get_host_vars(host), inventory.get_file_vars(). This means that both classes(ansible, ansible-playbook) will no longer have to manage finding and loading vars or facts, they will only address inventory and get what they need.
Also, if we also add get_facts_for_host(host) to inventory class, we can make /usr/bin/ansible ask for facts only if the user needs it (e.g. for debug purposes or wtvr).
I believe that both Runner, Playbook, Play and Task classes should only do scheduling, module and task calling, argument cleaning etc. and not managing or caching: variable files, getting facts, reading variables, etc.
I think I can work on this a little bit, so I can show you some code about that and you can comment it. Do you believe that something like that would be useful?
–Anastasis