ansible / ansible-modules-core

Ansible modules - these modules ship with ansible
1.3k stars 1.95k forks source link

local_action wait_for takes 5 minutes to run #1076

Closed tetherit closed 9 years ago

tetherit commented 9 years ago

I have this task:

- local_action:
    module: wait_for
      "host={{ ipaddress }} port=22 delay=10 connect_timeout=5 timeout=1800"
  sudo: false
  tags:
    - 'testwaitfor'

I can telnet to a running SSH just fine from this machine:

$ telnet 10.8.0.97 22
Trying 10.8.0.97...
Connected to 10.8.0.97.
Escape character is '^]'.
SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-8
^]

But when I try this from Ansible, I see this:

$ time ansible-playbook timeboxes.yml --tags testwaitfor -vvv

PLAY [carpc_rpi2] ************************************************************* 

GATHERING FACTS *************************************************************** 
<vpn.carpc_rpi2.zanview.com> ESTABLISH CONNECTION FOR USER: deployer
<vpn.carpc_rpi2.zanview.com> REMOTE_MODULE setup
<vpn.carpc_rpi2.zanview.com> EXEC ssh -C -v -o ForwardAgent=yes -o ControlPersist=30m -o ControlPath="/Users/Hackeron/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=deployer -o ConnectTimeout=10 vpn.carpc_rpi2.zanview.com /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=xkjuogremxhelybleroxixbnhtktppgt] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-xkjuogremxhelybleroxixbnhtktppgt; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python'"'"''
ok: [carpc_rpi2]

TASK: [common | wait_for "host=10.8.0.97 port=22 delay=10 connect_timeout=5 timeout=1800"] *** 
<vpn.carpc_rpi2.zanview.com> REMOTE_MODULE wait_for "host=10.8.0.97 port=22 delay=10 connect_timeout=5 timeout=1800"
<vpn.carpc_rpi2.zanview.com> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1428085244.93-113060526613695 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1428085244.93-113060526613695 && echo $HOME/.ansible/tmp/ansible-tmp-1428085244.93-113060526613695']
<vpn.carpc_rpi2.zanview.com> PUT /var/folders/jz/tbfhr91s2p53sx93zbbxb9jw0000gn/T/tmpSOVao5 TO /Users/Hackeron/.ansible/tmp/ansible-tmp-1428085244.93-113060526613695/wait_for
<vpn.carpc_rpi2.zanview.com> EXEC ['/bin/sh', '-c', u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /Users/Hackeron/.ansible/tmp/ansible-tmp-1428085244.93-113060526613695/wait_for; rm -rf /Users/Hackeron/.ansible/tmp/ansible-tmp-1428085244.93-113060526613695/ >/dev/null 2>&1']
ok: [carpc_rpi2 -> 127.0.0.1] => {"changed": false, "elapsed": 300, "path": null, "port": null, "search_regex": null, "state": "started"}

PLAY RECAP ******************************************************************** 
carpc_rpi2                 : ok=2    changed=0    unreachable=0    failed=0   

ansible-playbook timeboxes.yml --tags testwaitfor -vvv  299.68s user 0.63s system 98% cpu 5:05.81 total

I also tried to copy the python script from /Users/Hackeron/.ansible/tmp/ansible-tmp-1428085244.93-113060526613695/wait_for to ~/ and run that - and that too takes 5 minutes to run.

Why is it taking 5 minutes to check that SSH is up?

jder commented 9 years ago

You're passing {{ wait_delay }} for the delay argument, which is the "number of seconds to wait before starting to poll". Perhaps wait_delay is 300?

tetherit commented 9 years ago

You can seen the output it isn't:

TASK: [common | wait_for "host=10.8.0.97 port=22 delay=10 connect_timeout=5 timeout=1800"] *** 
REMOTE_MODULE wait_for "host=10.8.0.97 port=22 delay=10 connect_timeout=5 timeout=1800"

Updated the description to make that clearer.

jder commented 9 years ago

Ah, right, sorry. I think I figured out what's going on. Your syntax is not quite right. This:

    module: wait_for
      "host={{ ipaddress }} port=22 delay=10 connect_timeout=5 timeout=1800"

Passes these parameters to wait_for:

{
  'state': 'started',
  'connect_timeout': 5,
  'delay': 0,
  'host': '192.168.55.128 port=22 delay=10 connect_timeout=5 timeout=1800',
  'timeout': 300,
  'exclude_hosts': None,
  'search_regex': None,
  'path': None,
  'port': None
}

In other words, it thinks all your parameters are part of "host=...", and everything else is a default value. The defaults are, apparently, to wait for 5 minutes for nothing to happen. :) This works for me:

- local_action:
    module: wait_for host={{ ipaddress }} port=22 delay=10 connect_timeout=5 timeout=1800
tetherit commented 9 years ago

Ah, that did it, thank you! - Maybe the module should show a warning though like issue: https://github.com/ansible/ansible-modules-core/issues/400