The difference is that Ansible just installs the package you ask for in addition to other packages which may have been installed by a previous play or by other means, whereas the OP has developed a tool that ensures only the specific packages you ask for (and its dependencies) are installed.
One gotcha of Ansible is that removing a package from a playbook does not remove it from Ansible managed systems. You need to either manually remove the package or add another play that removes the package. The OP's tool does not have this limitation.