AFAIK Ansible core operates in terms of tasks and plays. The only API it provides is how to construct a list of tasks and how to execute it. One has no remote state/vars at the construction time and has to use "when" or shell logic at execution time as in YAML.