【问题标题】:Whan can I wait for after rebooting a VmWare VM in Ansible vsphere to ensure the state is booted?在 Ansible vsphere 中重新启动 VmWare VM 以确保状态已启动后,我可以等待什么?
【发布时间】:2019-03-29 00:09:56
【问题描述】:

我部署了一些低支持的操作系统,例如 Debian 9、Debian 8、Rehhat 6,7、Centos 7。

启动时不支持IP配置,所以我只添加了VLAN/虚拟网络接口,然后我使用vmware_vm_shell逐步配置操作系统。

我正在寻找的是等待远程 VM 上存在像 /proc/net/dev 这样的事件以继续其他步骤的技巧

到目前为止我尝试了什么:

- 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

最后一个等待代码块很糟糕(等待 N 秒),我想要更聪明的东西。

有什么想法吗?

如果我不等待,我有时会收到错误: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."} ,因为 VM 未启动。模板 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

【问题讨论】:

    标签: ansible vmware vsphere pyvmomi


    【解决方案1】:

    好的,找到自己了:)

      - 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-17
      • 1970-01-01
      相关资源
      最近更新 更多