Reputation: 293
I am implementing the logic for v2_playbook_on_task_start(self, task, is_conditional)
and want to get the host name of the target host where the task is supposed to run but the host name is not exposed in the Task object.
Is there a way to get the target host in this callback?
Upvotes: 0
Views: 476
Reputation: 293
Looking at how Ansible code is structured and how stuff gets executed in 2.3.1, it doesn't look like there is a way or a workaround to get the host name in the said callback.
A PlayIterator object and PlayContext is constructed inside TaskQueueManager.run(), then this PlayIterator object gets passed to a preselected "strategy" which does the task executions. The problem is inside the implementation of the these "strategies", for example the "free" strategy, the code loops through the list of hosts but does not pass the host details to the callback. It is not possible to manually template {{ inventory_hostname }}
using Templar either because Templar requires host name as an argument.
Upvotes: 1