@ -30,18 +30,21 @@ class AsyncPoller(object):
self . hosts_to_poll = [ ]
self . hosts_to_poll = [ ]
self . completed = False
self . completed = False
# Get job id and which hosts to poll again in the future
# flag to determine if at least one host was contacted
jid = Non e
self . active = Fals e
# True to work with & below
# True to work with & below
skipped = True
skipped = True
for ( host , res ) in results [ ' contacted ' ] . iteritems ( ) :
for ( host , res ) in results [ ' contacted ' ] . iteritems ( ) :
if res . get ( ' started ' , False ) :
if res . get ( ' started ' , False ) :
self . hosts_to_poll . append ( host )
self . hosts_to_poll . append ( host )
jid = res . get ( ' ansible_job_id ' , None )
jid = res . get ( ' ansible_job_id ' , None )
self . runner . setup_cache [ host ] [ ' ansible_job_id ' ] = jid
self . active = True
else :
else :
skipped = skipped & res . get ( ' skipped ' , False )
skipped = skipped & res . get ( ' skipped ' , False )
self . results [ ' contacted ' ] [ host ] = res
self . results [ ' contacted ' ] [ host ] = res
for ( host , res ) in results [ ' dark ' ] . iteritems ( ) :
for ( host , res ) in results [ ' dark ' ] . iteritems ( ) :
self . runner . setup_cache [ host ] [ ' ansible_job_id ' ] = ' '
self . results [ ' dark ' ] [ host ] = res
self . results [ ' dark ' ] [ host ] = res
if not skipped :
if not skipped :
@ -49,14 +52,13 @@ class AsyncPoller(object):
raise errors . AnsibleError ( " unexpected error: unable to determine jid " )
raise errors . AnsibleError ( " unexpected error: unable to determine jid " )
if len ( self . hosts_to_poll ) == 0 :
if len ( self . hosts_to_poll ) == 0 :
raise errors . AnsibleError ( " unexpected error: no hosts to poll " )
raise errors . AnsibleError ( " unexpected error: no hosts to poll " )
self . jid = jid
def poll ( self ) :
def poll ( self ) :
""" Poll the job status.
""" Poll the job status.
Returns the changes in this iteration . """
Returns the changes in this iteration . """
self . runner . module_name = ' async_status '
self . runner . module_name = ' async_status '
self . runner . module_args = " jid= %s " % self . jid
self . runner . module_args = " jid= {{ ansible_job_id}} "
self . runner . pattern = " * "
self . runner . pattern = " * "
self . runner . background = 0
self . runner . background = 0
self . runner . complex_args = None
self . runner . complex_args = None
@ -75,13 +77,14 @@ class AsyncPoller(object):
self . results [ ' contacted ' ] [ host ] = res
self . results [ ' contacted ' ] [ host ] = res
poll_results [ ' contacted ' ] [ host ] = res
poll_results [ ' contacted ' ] [ host ] = res
if res . get ( ' failed ' , False ) or res . get ( ' rc ' , 0 ) != 0 :
if res . get ( ' failed ' , False ) or res . get ( ' rc ' , 0 ) != 0 :
self . runner . callbacks . on_async_failed ( host , res , self . jid)
self . runner . callbacks . on_async_failed ( host , res , self . runner. setup_cache [ host ] [ ' ansible_ job_ id' ] )
else :
else :
self . runner . callbacks . on_async_ok ( host , res , self . jid)
self . runner . callbacks . on_async_ok ( host , res , self . runner. setup_cache [ host ] [ ' ansible_ job_ id' ] )
for ( host , res ) in results [ ' dark ' ] . iteritems ( ) :
for ( host , res ) in results [ ' dark ' ] . iteritems ( ) :
self . results [ ' dark ' ] [ host ] = res
self . results [ ' dark ' ] [ host ] = res
poll_results [ ' dark ' ] [ host ] = res
poll_results [ ' dark ' ] [ host ] = res
self . runner . callbacks . on_async_failed ( host , res , self . jid )
if host in self . hosts_to_poll :
self . runner . callbacks . on_async_failed ( host , res , self . runner . setup_cache [ host ] . get ( ' ansible_job_id ' , ' XX ' ) )
self . hosts_to_poll = hosts
self . hosts_to_poll = hosts
if len ( hosts ) == 0 :
if len ( hosts ) == 0 :
@ -92,7 +95,7 @@ class AsyncPoller(object):
def wait ( self , seconds , poll_interval ) :
def wait ( self , seconds , poll_interval ) :
""" Wait a certain time for job completion, check status every poll_interval. """
""" Wait a certain time for job completion, check status every poll_interval. """
# jid is None when all hosts were skipped
# jid is None when all hosts were skipped
if self . jid is Non e:
if not self . activ e:
return self . results
return self . results
clock = seconds - poll_interval
clock = seconds - poll_interval
@ -103,7 +106,7 @@ class AsyncPoller(object):
for ( host , res ) in poll_results [ ' polled ' ] . iteritems ( ) :
for ( host , res ) in poll_results [ ' polled ' ] . iteritems ( ) :
if res . get ( ' started ' ) :
if res . get ( ' started ' ) :
self . runner . callbacks . on_async_poll ( host , res , self . jid, clock )
self . runner . callbacks . on_async_poll ( host , res , self . runner. setup_cache [ host ] [ ' ansible_ job_ id' ] , clock )
clock = clock - poll_interval
clock = clock - poll_interval