Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VMware Module - vmware_guest_move #42149

Merged
merged 6 commits into from
Jul 27, 2018
Merged

VMware Module - vmware_guest_move #42149

merged 6 commits into from
Jul 27, 2018

Conversation

imjoseangel
Copy link
Contributor

SUMMARY

Module to Move VMs between Folders in VCenter Fixes #39165 Continues #42059. Sorry for the Error

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

vmware_guest_move

ANSIBLE VERSION
ansible 2.5.5
  config file = /Users/imjoseangel/Source/sandbox/ansible.cfg
  configured module search path = ['/Users/imjoseangel/Source/sandbox/library', '/Users/imjoseangel/.ansible/library', '/usr/share/ansible/library']
  ansible python module location = /Users/imjoseangel/Source/ansible/lib/python3.6/site-packages/ansible
  executable location = /Users/imjoseangel/Source/ansible/bin/ansible
  python version = 3.6.5 (default, Apr 25 2018, 14:23:58) [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]
ADDITIONAL INFORMATION
None

@imjoseangel
Copy link
Contributor Author

@Akasurde Could you please re-check? Sorry for the mistake. The rebase stuff drives me crazy

@ansibot
Copy link
Contributor

ansibot commented Jun 30, 2018

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 cloud community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. new_module This PR includes a new module. new_plugin This PR includes a new plugin. python3 support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests. vmware VMware community labels Jun 30, 2018
@ansibot
Copy link
Contributor

ansibot commented Jun 30, 2018

@bedecarroll @chrrrles @dav1x @garbled1 @jjahns @kamsz @lrivallain @nafpliot-ibm @nerzhul @pdellaert @rhoop @ritzk @stravassac @tchernomax @warthog9 @woshihaoren

As a maintainer of a module in the same namespace this new module has been submitted to, your vote counts for shipits. Please review this module and add shipit if you would like to see it merged.

click here for bot help

@Akasurde Akasurde removed needs_triage Needs a first human triage before being processed. new_plugin This PR includes a new plugin. labels Jul 2, 2018
@Alex5252
Copy link

Alex5252 commented Jul 8, 2018

Can you give a working playbook, and a description of the environment so that I can test it?

With my playbook -

---
- hosts: localhost

  tasks:

    - name: Move Virtual Machine Files
      vmware_guest_move:
        hostname: vc-hostname
        username: administrator@vsphere.local
        password: password
        validate_certs: False
        datacenter: DC1
        name: test-test1
        dest_folder: /DC1/dc-folder/

I receive error -

user@host:~/docs/scripts/ansible/02-vmware/vc1/91-vmware_guest_move$ ./vmware_guest_move.sh
ansible-playbook 2.7.0.dev0 (devel 07adeff665) last updated 2018/07/07 23:02:15 (GMT +300)
  config file = None
  configured module search path = [u'/home/user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/docs/scripts/ansible-git/ansible/lib/ansible
  executable location = /home/user/docs/scripts/ansible-git/ansible/bin/ansible-playbook
  python version = 2.7.12 (default, Dec  4 2017, 14:50:18) [GCC 5.4.0 20160609]
No config file found; using defaults
 [WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


PLAYBOOK: vmware_guest_move.yml ***********************************************************************************************************************
1 plays in vmware_guest_move.yml

PLAY [localhost] **************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************
task path: /home/user/docs/scripts/ansible/02-vmware/vc1/91-vmware_guest_move/vmware_guest_move.yml:2
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: user
<127.0.0.1> EXEC /bin/sh -c 'echo ~user && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/user/.ansible/tmp/ansible-tmp-1531041390.6-53607694340878 `" && echo ansible-tmp-1531041390.6-53607694340878="` echo /home/user/.ansible/tmp/ansible-tmp-1531041390.6-53607694340878 `" ) && sleep 0'
Using module file /home/user/docs/scripts/ansible-git/ansible/lib/ansible/modules/system/setup.py
<127.0.0.1> PUT /home/user/.ansible/tmp/ansible-local-252846MNlZM/tmpv9wE1S TO /home/user/.ansible/tmp/ansible-tmp-1531041390.6-53607694340878/setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/user/.ansible/tmp/ansible-tmp-1531041390.6-53607694340878/ /home/user/.ansible/tmp/ansible-tmp-1531041390.6-53607694340878/setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /home/user/.ansible/tmp/ansible-tmp-1531041390.6-53607694340878/setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/user/.ansible/tmp/ansible-tmp-1531041390.6-53607694340878/ > /dev/null 2>&1 && sleep 0'
ok: [localhost]
META: ran handlers

TASK [Move Virtual Machine Files] *********************************************************************************************************************
task path: /home/user/docs/scripts/ansible/02-vmware/vc1/91-vmware_guest_move/vmware_guest_move.yml:6
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: user
<127.0.0.1> EXEC /bin/sh -c 'echo ~user && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/user/.ansible/tmp/ansible-tmp-1531041391.58-235428649531005 `" && echo ansible-tmp-1531041391.58-235428649531005="` echo /home/user/.ansible/tmp/ansible-tmp-1531041391.58-235428649531005 `" ) && sleep 0'
Using module file /home/user/docs/scripts/ansible-git/ansible/lib/ansible/modules/cloud/vmware/vmware_guest_move.py
<127.0.0.1> PUT /home/user/.ansible/tmp/ansible-local-252846MNlZM/tmptmqr5S TO /home/user/.ansible/tmp/ansible-tmp-1531041391.58-235428649531005/vmware_guest_move.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/user/.ansible/tmp/ansible-tmp-1531041391.58-235428649531005/ /home/user/.ansible/tmp/ansible-tmp-1531041391.58-235428649531005/vmware_guest_move.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /home/user/.ansible/tmp/ansible-tmp-1531041391.58-235428649531005/vmware_guest_move.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/user/.ansible/tmp/ansible-tmp-1531041391.58-235428649531005/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
  File "/tmp/ansible_1jGG4t/ansible_module_vmware_guest_move.py", line 201, in main
    move_task = folder.MoveInto([vm_to_move])

fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "datacenter": "DC1",
            "dest_folder": "/DC1/user2",
            "hostname": "vc-hostname",
            "name": "test-test1",
            "name_match": "first",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 443,
            "username": "administrator@vsphere.local",
            "uuid": null,
            "validate_certs": false
        }
    },
    "msg": "Failed to move VM with exception 'NoneType' object has no attribute 'MoveInto'"
}
        to retry, use: --limit @/home/user/docs/scripts/ansible/02-vmware/vc1/91-vmware_guest_move/vmware_guest_move.retry

PLAY RECAP ********************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1

@imjoseangel
Copy link
Contributor Author

imjoseangel commented Jul 8, 2018

You get that error because the destination folder doesn't exist. Could you please check if yours exist? We can consider checking the destination folder and even creating it if it doesn't exist beforehand. What do you think?

@Akasurde
Copy link
Member

Akasurde commented Jul 8, 2018

Yes. I checked, if folder does not exist then we get this error. I disagree to create destination folder as - firstly, creating folder will puzzle user and secondly, there is an existing module for creating folder. Thanks.

@Alex5252
Copy link

Alex5252 commented Jul 8, 2018

I correct playbook to this form:

---
- hosts: localhost
  tasks:
    - name: Move Virtual Machine Files
      vmware_guest_move:
        hostname: vc-hostname
        username: administrator@vsphere.local
        password: password
        validate_certs: False
        datacenter: DC1
        name: test-test1
        dest_folder: /DC1/vm/dc-folder/

This playbook performed the task of migrating the virtual machine to the "VM and Template Folder".

The documentation https://docs.ansible.com/ansible/2.5/modules/vcenter_folder_module.html of the vcenter_folder module has a folder_type option with the "vm" option. And the module vmware_guest_move folder type is contained in the variable "dest_folder" and it hit me. It would be nice to render a folder type from the variable "dest_folder", folder_type with the "vm" parameter and make it default.
In the documentation, the example "dest_folder: "/path/to/new/folder/where/we/want/vm"" is also thrown off the correct path. If the documentation were written like this: "dest_folder: "/DataCenter/vm/path/to/new/folder/where/we/want"" it would also be unclear, but the path would be logically correct.

@imjoseangel
Copy link
Contributor Author

It can be changed but don't you think the documentation is clear on this part?

            - 'Examples:'
            - '   dest_folder: /ha-datacenter/vm'
            - '   dest_folder: ha-datacenter/vm'
            - '   dest_folder: /datacenter1/vm'
            - '   dest_folder: datacenter1/vm'
            - '   dest_folder: /datacenter1/vm/folder1'
            - '   dest_folder: datacenter1/vm/folder1'
            - '   dest_folder: /folder1/datacenter1/vm'
            - '   dest_folder: folder1/datacenter1/vm'
            - '   dest_folder: /folder1/datacenter1/vm/folder2'

@Alex5252
Copy link

Alex5252 commented Jul 9, 2018

I looked at several implementations of modules, done in different ways.
I propose to correct the example in the documentation from "/path/to/new/folder/where/we/want/vm" to "/DataCenter/vm/path/to/new/folder/where/we/want" to make the example logical.
I checked and the module works correctly. I suggest merge in the main code base.

@imjoseangel
Copy link
Contributor Author

No problem at all. Do you agree @Akasurde ? Please confirm and I will update documentation.

@@ -0,0 +1,3 @@
posix/ci/cloud/group1/vcenter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this group4 and remove smoketest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done Thanks

@Akasurde
Copy link
Member

Yes. I agree to change the path in example. Added a small comment about placing test in group4.

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jul 18, 2018
@@ -0,0 +1,2 @@
posix/ci/cloud/group4/vcenter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is changed now,

You need to place under

shippable/vcenter/group1 instead of posix/ci/cloud/group4/vcenter

@Akasurde
Copy link
Member

Akasurde commented Jul 27, 2018

@imjoseangel could you please work on suggested changes and let me know ?

@imjoseangel
Copy link
Contributor Author

@Akasurde changed. Thanks!

@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jul 27, 2018
@Akasurde Akasurde merged commit 711dd9f into ansible:devel Jul 27, 2018
@Akasurde
Copy link
Member

@imjoseangel Thanks for the contribution.

@imjoseangel
Copy link
Contributor Author

Thank you @Akasurde for the experience and learnings!

@imjoseangel imjoseangel deleted the module/vmware_guest_move branch July 27, 2018 18:31
alikins added a commit that referenced this pull request Aug 8, 2018
* devel: (50 commits)
  Add new module for Redfish APIs (#41656)
  VMware Module - vmware_guest_move (#42149)
  Lenovo port to persistence 1 (#43194)
  VMware: new module: vmware_guest_boot_manager (#40609)
  fixes #42042 (#42939)
  VMware: new module: vmware_category_facts (#39894)
  VMware: Dynamic Inventory plugin (#37456)
  Validate and reject if csr_path is not supplied when provider is not assertonly (#41385)
  VMware: new module : vmware_guest_custom_attributes (#38114)
  VMware: new module: vmware_guest_attribute_defs (#38144)
  VMware: Fix mark as virtual machine method (#40521)
  Ironware: Deprecate provider, support network_cli (#43285)
  feat: Add a enable_accelerated_networking flag in module + tests; fixes #41218  (#42109)
  fixing aiuth source (#42923)
  VMware: handle special characters in datacenter name (#42922)
  VMware: update examples in vmware_vm_shell (#42410)
  VMWare: refactor vmware_vm_shell module (#39957)
  VMware: additional VSAN facts about Hostsystem (#40456)
  nxos cliconf plugin refactor (#43203)
  Correcting conditionals looping (#43331)
  ...
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.7 This issue/PR affects Ansible v2.7 cloud community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. new_contributor This PR is the first contribution by a new community member. new_module This PR includes a new module. python3 support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests. vmware VMware community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vmware_guest option to move an existing vm to a different folder
4 participants