This could be handled in the configuration phase. That phase is synchronous with between user order and beginning the clone operations of the system. There are a few posts in here around hostname or IP address with configuration phase that you may find useful for starting points.
I have tried adding in the task in all phases of the workflow - but it appears to clone the machine first and then run the task which is what i to prevent depending on the outcome of the task, i.e. something exists already.
When you state “triggered the workflow vai the catalog”, are you stating you’ve kicked off a new VM build? Configuration phase would only execute on a new build just prior to the clone of the system. If you manually run a workflow against a system post, there is no config phase.
What version are you on of Morpheus? Does it work if you select the workflow using standard instances? What about different scripting language besides Ansible? Curious if the command bus of Ansible can’t do anything since there is no agent at that stage.
Have you tried expanding the “Provision” group on the History tab? I notice your screen shot only shows it collapsed. I’m fairly sure I’ve done something similar to what you are trying to do and it worked just fine… The Task would show up before “Deploy Virtual Machine” in the list of things it is doing inside the “Provision” item you are showing collapsed…