Having trouble with VMWare vMotion Playbook

Hello, I have installed the community.vmware module for my playbook. I am currently using 4.0. I am trying to run an ansible script where it moves one virtual machine from one host to another host using vMotion. However, every time I run the script, I receive the error: ‘community.vmware.vmware_vmotion’ is not a valid attribute for a Play.

How is that possible when community.vmware.vmware_vmotion is listed as a module on the documentation? Listed below:

VMware Ansible Documentation

.

Below is my script, and I don’t know what to do to fix this:

  • name: Perform vMotion of virtual machine
    community.vmware.vmware_vmotion:
    hostname: ‘{{ vcenter_hostname }}’
    username: ‘{{ vcenter_username }}’
    password: ‘{{ vcenter_password }}’
    vm_name: ‘vm_name_as_per_vcenter’
    destination_host: ‘destination_host_as_per_vcenter’
    delegate_to: localhost

I don’t see if your indentation is correct. Either it isn’t or the forum just doesn’t show it correct (to me).

- name: Perform vMotion of virtual machine
    community.vmware.vmware_vmotion:
      hostname: ‘{{ vcenter_hostname }}’
      username: ‘{{ vcenter_username }}’
      password: ‘{{ vcenter_password }}’
      vm_name: ‘vm_name_as_per_vcenter’
      destination_host: ‘destination_host_as_per_vcenter’
    delegate_to: localhost

If you think your indentation is correct, please show a little bit more of your playbook. And use preformatted text so the forum doesn’t “improve” formatting :stuck_out_tongue_winking_eye:

1 Like

Hi,

is not a valid attribute for a Play

means you are trying to pass a module name (used in tasks) at play level.

In short, a playbook is composed of one or more plays, each of them having one or more tasks (also handlers, vars, …), so something like that in your case:

- name: myPlay
  hosts: myHosts
  tasks:
    - name: Perform vMotion of virtual machine
      community.vmware.vmware_vmotion:
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        vm_name: vm_name_as_per_vcenter
        destination_host: destination_host_as_per_vcenter
      delegate_to: localhost

It may obviously vary a lot; it’s just a barebone example. For instance, you may whish to use become: true at play level, or define vars, etc…

1 Like

Yes, the way you have it is how I have idented my script.

Thank you so much, I appreciate it. Silly mistake on my end, but that did help me get past that error. Thanks again.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.