1

I deploy some low supported OS like Debian 9, Debian 8, Rehhat 6,7, Centos 7.

The IP configuration is unsupported at boot time, so I add only the VLAN/virtual network interface, then I use vmware_vm_shell to configure the OS step by step.

What I'm looking for is a trick to wait for an event like /proc/net/dev exists on remote VM to continue other steps

What I tried so far :

- hosts: localhost
  tasks:
  - name: Create a virtual machine "{{ vm_name }}"
    vmware_guest:
      datacenter: '{{ datacenter }}'
      hostname: '{{ vcenter }}'
      username: "{{ login }}"
      password: "{{ passwd }}"
      folder: "{{ folder }}"
      name: "{{ vm_name }}"
      template: '{{ template }}'
      cluster: "{{ cluster }}"
      state: poweredon
      disk:
      - size_gb: "{{ disksizeGB }}"
        datastore: '{{ datastore }}'
      hardware:
        memory_mb: '{{ ramsizeMB }}'
        num_cpus: '{{ vcpu_num }}'
        hotadd_cpu: True
        hotremove_cpu: True
        hotadd_memory: True
      networks: '{{ vlans }}'
      #wait_for_ip_address: yes # ERR there's ifaces, but not ip at this time
    register: deploy

  - name: Wait for server to start
    local_action:
      module: wait_for
        timeout=15
    when: deploy.changed

The last wait code block sucks (waiting N seconds) , I would like something smarter.

Any idea ?

If I don't wait, I sometimes get error : fatal: [localhost]: FAILED! => {"changed": false, "msg": "VMWareTools is not installed or is not running in the guest. VMware Tools are necessary to run this module."} because the VM is not booted. The template have vmware-tools.

https://docs.ansible.com/ansible/2.6/modules/vmware_guest_module.html#vmware-guest-module https://docs.ansible.com/ansible/latest/modules/vmware_vm_shell_module.html

1 Answers1

1

Ok, found myself :)

  - name: wait for server to boot
    vmware_vm_shell:
      datacenter: '{{ datacenter }}'
      hostname: 'vcenter{{ vcenter }}'
      username: "{{ login }}"
      password: "{{ passwd }}"
      validate_certs: False
      folder: "{{ folder }}"
      vm_id: "{{ vm_name }}"
      cluster: "{{ cluster }}"
      vm_password: '{{ passwd }}'
      vm_username: root
      vm_shell: '/bin/sleep'
      vm_shell_args: 0
    when: deploy.changed and 'debian' in distro
    register: has_reboot
    until: has_reboot.failed != 'true'
    delay: 2
    retries: 150