How to i get list of all hosts in playbook_on_task_start ?

52 views
Skip to first unread message

Ritesh Shetty

unread,
Apr 25, 2016, 4:17:16 PM4/25/16
to Ansible Project
I used to have this code in ansible 1.x 

def playbook_on_task_start(self, name, is_conditional):

play = getattr(self, 'play', None)
task = getattr(self, 'task', None)

if play is not None and task is not None:
for host in play._play_hosts:
print host


But with ansible 2.0 looks like its all changed. My aim is to get list of hosts when task starts for auditing purposes
Can some one please help !




Ritesh Shetty

unread,
Apr 25, 2016, 10:38:35 PM4/25/16
to Ansible Project
play.hosts works !

Ritesh Shetty

unread,
Jun 2, 2016, 9:50:54 PM6/2/16
to Ansible Project
there is a problem to this .... 

if my hostvars declared esx_host and under that the host is lets say 10.16.1.3 then self.play.hosts gives esx_host and not 10.16.1.3 

runner_on_ok gets the right host as a parameter

So back to finding a good way ! I am using ansible 1.0 and alos using the adaptors as recommended 

def v2_playbook_on_task_start(self, task, is_conditional):
self.task = task
self.playbook_on_task_start(task, is_conditional)
Reply all
Reply to author
Forward
0 new messages