Why doesn't this task to check when a server has booted work?

23 views
Skip to first unread message

RobertF

unread,
Jan 7, 2020, 4:55:55 PM1/7/20
to Ansible Project
I have an Ansible playbook for creating [Linode](https://linode.com) servers.  The problem I'm having is that my playbook isn't able to determine when the new server is up.  I'm using Ansible 2.8.4.  My playbook is as follows:

    ---
    hosts: 127.0.0.1
    gather_facts: False

    - name: create server
      linode_v4:
        label: "{{ host_name }}_{{ 100 | random }}"
        access_token: "{{ linode_api4_key }}"
        type: "{{ plan_1GB }}"
        region: "{{ region_us_central }}"
        image: "{{ image_debian_10 }}"
        root_pass: "{{ linode_root_password }}"
        authorized_keys: "{{ my_ssh_public_key }}"
        tags: "inventory.ini"
        state: present
      register: linode

    - name: save new server's ip address to a fact
      set_fact: ip_addr={{ linode.instance.ipv4 }}
      tags: always

    - debug:
        var: ip_addr

    - name: wait until new server is up
      wait_for:
        state: started
        host: "{{ ip_addr }}"
        port: 22
        delay: 2
        timeout: 600
        msg: "Server port is not listening"
      tags: always

I also tried it this way:

    - name: wait until new server is up
      local_action:
        module: wait_for
        state: started
        host: "{{ ip_addr }}"
        port: 22
        delay: 1
        timeout: 100


I've tried doing it using a wait_for and also via local_action but neither one is working.  The playbook never returns from the wait for task.  I monitor my Linode dashboard as the playbook runs and I can see that that IP address I'm feeding to the task via "ip_addr" is correct and the dashboard also shows me when the server is up.  Can anyone see what I doing wrong?  Thanks!

Jean-Yves LENHOF

unread,
Jan 7, 2020, 5:24:13 PM1/7/20
to ansible...@googlegroups.com
Hi,

You should probably use "wait_for_connection" module instead of the one
you use

This is how I use it :

- hosts: newly_managed_vms
  become: yes
  become_user: root
  remote_user: ansible
  gather_facts: no   # servers could be not available yet
  tasks:

  - name: "Wait for server to power up"
    wait_for_connection:
      sleep: 5
      timeout: 600

  - name: "Gather facts for first time"
    setup:

Regards,

JYL

RobertF

unread,
Jan 8, 2020, 7:10:18 PM1/8/20
to Ansible Project
Thanks Jean-Yves!
Reply all
Reply to author
Forward
0 new messages