Coder Social home page Coder Social logo

qsypoq / ansible-vmware-workstation-fusion-pro-modules Goto Github PK

View Code? Open in Web Editor NEW
55.0 55.0 11.0 228 KB

Ansible meet VMware Workstation/Fusion Pro

Home Page: https://magnier.io/developing-vmware-workstation-pro-ansible-module/

License: MIT License

PowerShell 30.59% Python 69.41%
ansible ansible-modules vmware-workstation

ansible-vmware-workstation-fusion-pro-modules's Introduction

ansible-vmware-workstation-fusion-pro-modules's People

Contributors

qsypoq avatar vmarkusk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ansible-vmware-workstation-fusion-pro-modules's Issues

Create inventory plugin

Idea coming from Reddit
How:

  • Call VM list from API, parse it and grab VM name and other usefull non-api-retrievable datas from VMX, generate.

target_vm_name not working on python 3.7

When interpreter_python is set to python3.7 the target_vm_name trick does not work :

The full traceback is:
Traceback (most recent call last):
  File "/home/qsypoq/.ansible/tmp/ansible-tmp-1597846994.942776-2808-172921044836590/AnsiballZ_unix_vmware_desktop_vmmgmt.py", line 102, in <module>
    _ansiballz_main()
  File "/home/qsypoq/.ansible/tmp/ansible-tmp-1597846994.942776-2808-172921044836590/AnsiballZ_unix_vmware_desktop_vmmgmt.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/qsypoq/.ansible/tmp/ansible-tmp-1597846994.942776-2808-172921044836590/AnsiballZ_unix_vmware_desktop_vmmgmt.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible.modules.unix_vmware_desktop_vmmgmt', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.7/runpy.py", line 205, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_unix_vmware_desktop_vmmgmt_payload_a9661w92/ansible_unix_vmware_desktop_vmmgmt_payload.zip/ansible/modules/unix_vmware_desktop_vmmgmt.py", line 210, in <module>
  File "/tmp/ansible_unix_vmware_desktop_vmmgmt_payload_a9661w92/ansible_unix_vmware_desktop_vmmgmt_payload.zip/ansible/modules/unix_vmware_desktop_vmmgmt.py", line 207, in main
  File "/tmp/ansible_unix_vmware_desktop_vmmgmt_payload_a9661w92/ansible_unix_vmware_desktop_vmmgmt_payload.zip/ansible/modules/unix_vmware_desktop_vmmgmt.py", line 166, in run_module
FileNotFoundError: [Errno 2] No such file or directory: 'DHCV3BKA93JSTMAGUO1JT3L95QGPK9TA'
fatal: [vmware-workstation-linux]: FAILED! => {
    "changed": false,
    "module_stderr": "Shared connection to 172.20.20.30 closed.\r\n",
    "module_stdout": "Traceback (most recent call last):\r\n  File \"/home/qsypoq/.ansible/tmp/ansible-tmp-1597846994.942776-2808-172921044836590/AnsiballZ_unix_vmware_desktop_vmmgmt.py\", line 102, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/qsypoq/.ansible/tmp/ansible-tmp-1597846994.942776-2808-172921044836590/AnsiballZ_unix_vmware_desktop_vmmgmt.py\", line 94, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/qsypoq/.ansible/tmp/ansible-tmp-1597846994.942776-2808-172921044836590/AnsiballZ_unix_vmware_desktop_vmmgmt.py\", line 40, in invoke_module\r\n    runpy.run_module(mod_name='ansible.modules.unix_vmware_desktop_vmmgmt', init_globals=None, run_name='__main__', alter_sys=True)\r\n  File \"/usr/lib/python3.7/runpy.py\", line 205, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/lib/python3.7/runpy.py\", line 96, in _run_module_code\r\n    mod_name, mod_spec, pkg_name, script_name)\r\n  File \"/usr/lib/python3.7/runpy.py\", line 85, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_unix_vmware_desktop_vmmgmt_payload_a9661w92/ansible_unix_vmware_desktop_vmmgmt_payload.zip/ansible/modules/unix_vmware_desktop_vmmgmt.py\", line 210, in <module>\r\n  File \"/tmp/ansible_unix_vmware_desktop_vmmgmt_payload_a9661w92/ansible_unix_vmware_desktop_vmmgmt_payload.zip/ansible/modules/unix_vmware_desktop_vmmgmt.py\", line 207, in main\r\n  File \"/tmp/ansible_unix_vmware_desktop_vmmgmt_payload_a9661w92/ansible_unix_vmware_desktop_vmmgmt_payload.zip/ansible/modules/unix_vmware_desktop_vmmgmt.py\", line 166, in run_module\r\nFileNotFoundError: [Errno 2] No such file or directory: 'DHCV3BKA93JSTMAGUO1JT3L95QGPK9TA'\r\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

In python2 the currentvmx value is set as expected, for example /home/qsypoq/vmware/wintest/wintest.vmx but in python3 it got the target VM ID instead, in my case DHCV3BKA93JSTMAGUO1JT3L95QGPK9TA so it fails when trying to open it.

After tests it looks like when getting the informations from API the vm.values array is inverted:

  • Python2: vmx_path, vm_ID
  • Python3: vm_ID, vmx_path

Linux - VMs can't be cloned Error 409

Hi
This is my setup Arch linux:

localhost

  • runs ansible
  • runs vmware workstation

Goal:
Clone "AnTemp" VM (really long id - see below) to an new VM and give the VM a new hostname.

Problem:

  • Cloneing does not work.

When i try to use the "clone VMs" the connection suceeds but none of my VMs cloned. Instead i recive:

`
manuel@R920:~/.ansible$ansible-playbook -i hosts an_clone_vm_loadb.yml -vvv
ansible-playbook 2.10.3
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/manuel/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.8/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 3.8.6 (default, Sep 30 2020, 04:00:38) [GCC 10.2.0]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /home/manuel/.ansible/hosts as it did not pass its verify_file() method
script declined parsing /home/manuel/.ansible/hosts as it did not pass its verify_file() method
auto declined parsing /home/manuel/.ansible/hosts as it did not pass its verify_file() method
Parsed /home/manuel/.ansible/hosts inventory source with ini plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

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

PLAY [localhost] ******************************************************************************************************************************************************************************************************************************************************
META: ran handlers

TASK [Clone] **********************************************************************************************************************************************************************************************************************************************************
task path: /home/manuel/.ansible/an_clone_vm_loadb.yml:7
ESTABLISH LOCAL CONNECTION FOR USER: manuel
EXEC /bin/sh -c 'echo ~manuel && sleep 0'
EXEC /bin/sh -c '( umask 77 && mkdir -p "echo /home/manuel/.ansible/tmp"&& mkdir "echo /home/manuel/.ansible/tmp/ansible-tmp-1606252755.303682-106025-67445614140385" && echo ansible-tmp-1606252755.303682-106025-67445614140385="echo /home/manuel/.ansible/tmp/ansible-tmp-1606252755.303682-106025-67445614140385" ) && sleep 0'
Attempting python interpreter discovery
EXEC /bin/sh -c 'echo PLATFORM; uname; echo FOUND; command -v '"'"'/usr/bin/python'"'"'; command -v '"'"'python3.7'"'"'; command -v '"'"'python3.6'"'"'; command -v '"'"'python3.5'"'"'; command -v '"'"'python2.7'"'"'; command -v '"'"'python2.6'"'"'; command -v '"'"'/usr/libexec/platform-python'"'"'; command -v '"'"'/usr/bin/python3'"'"'; command -v '"'"'python'"'"'; echo ENDFOUND && sleep 0'
EXEC /bin/sh -c '/usr/bin/python && sleep 0'
Python interpreter discovery fallback (unable to get Linux distribution/version info)
Using module file /home/manuel/.ansible/collections/ansible_collections/qsypoq/vmware_desktop/plugins/modules/unix_vmware_desktop_vmmgmt.py
PUT /home/manuel/.ansible/tmp/ansible-local-1060167k_pq3u1/tmpgo0jvcm5 TO /home/manuel/.ansible/tmp/ansible-tmp-1606252755.303682-106025-67445614140385/AnsiballZ_unix_vmware_desktop_vmmgmt.py
EXEC /bin/sh -c 'chmod u+x /home/manuel/.ansible/tmp/ansible-tmp-1606252755.303682-106025-67445614140385/ /home/manuel/.ansible/tmp/ansible-tmp-1606252755.303682-106025-67445614140385/AnsiballZ_unix_vmware_desktop_vmmgmt.py && sleep 0'
EXEC /bin/sh -c '/usr/bin/python /home/manuel/.ansible/tmp/ansible-tmp-1606252755.303682-106025-67445614140385/AnsiballZ_unix_vmware_desktop_vmmgmt.py && sleep 0'
EXEC /bin/sh -c 'rm -f -r /home/manuel/.ansible/tmp/ansible-tmp-1606252755.303682-106025-67445614140385/ > /dev/null 2>&1 && sleep 0'
[WARNING]: Module did not set no_log for password
[WARNING]: Platform linux on host localhost is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change the meaning of that path. See
https://docs.ansible.com/ansible/2.10/reference_appendices/interpreter_discovery.html for more information.
fatal: [localhost]: FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"invocation": {
"module_args": {
"action": "clone",
"api_port": "8697",
"api_url": "http://127.0.0.1",
"memory_mb": null,
"name": "An-LoadBalancer",
"num_cpus": null,
"password": "Ansible123#",
"target_vm": "P6VIGOQK5E0RBNAU61C7DQFQFKFBPLE9",
"target_vm_name": "",
"timeout": 30,
"username": "ansible",
"validate_certs": false
}
},
"msg": "HTTP Error 409: Conflict"
}

PLAY RECAP ************************************************************************************************************************************************************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
`

my host file:

[controller]
ans-control ansible_connection=local

[local]
localhost ansible_connection=local

[loadbalancer]
lb01 ansible_user=ansible

[webserver]
app01 ansible_user=ansible
app02 ansible_user=ansible

vmrest ist running as user manuel on the machine. If i run it as root it can not be accessed by ansible i think. (I get no ouput from the list all VMs playbook)

The vmlist plaxbook works and i get my machine ids.

My playbook in question (not working).

`

  • hosts: localhost
    gather_facts: no
    collections:
    • qsypoq.vmware_desktop
      tasks:

    • name: "Clone"
      unix_vmware_desktop_vmmgmt:
      target_vm: "P6VIGOQK5E0RBNAU61C7DQFQFKFBPLE9"
      action: clone
      name: "An-LoadBalancer"
      username: "ansible"
      password: "Ansible123#"
      `

Here the target_vm should be cloneded to the new one with the name An-Load-Balancer. Can i also change the Hostname of the machine while cloning ?

Working:
`

  • hosts: localhost
    gather_facts: no
    collections:
    • qsypoq.vmware_desktop
      tasks:

    • name: "List all VMs"
      unix_vmware_desktop_vminfos:
      username: "ansible"
      password: "Ansible123#"
      `

Why does this error occur and how can i fix it ?
Thanks!

Add last API features

New features found in API's documentation:

VM Management

Get the VM config params

    • Code
    • Doc py
    • Doc readme

Return the restrictions information of the VM

    • Code
    • Doc py
    • Doc readme

Register VM to the VM library

    • Code
    • Doc py
    • Doc readme

Update the VM config params

This part can't be used/tested yet because of a bug on API's side but it's done

    • Code
    • Doc py
    • Doc readme

Add last API features

New features found in API's documentation:

VM Management

Get the VM config params

    • Code
    • Doc py
    • Doc readme

Return the restrictions information of the VM

    • Code
    • Doc py
    • Doc readme

Register VM to the VM library

    • Code
    • Doc py
    • Doc readme

Update the VM config params

This part can't be used/tested yet because of a bug on API's side

    • Code
    • Doc py
    • Doc readme

Basic 'get started' info

Hi there, love the project idea.

Myself not being an Ansible expert, it would be great to have a quick doc to do some basic task.

Failed to connect to the host via ssh: ssh: connect to host x.y.x.a port 22: Operation timed out"

Hello,

Is the below incorrect?

Playbook:

  • hosts: my_vmware_pro
    gather_facts: no
    collections:
    • qsypoq.vmware_desktop
      tasks:

    • name: "List all VMs"
      win_vmware_desktop_vminfos:
      username: "john.smith"
      password: "password1234"
      api_url: "http://192.168.1.0.1"
      api_port: "8697"
      validate_certs: no

Inventory file:

[VMWare_Servers]
my_vmware_pro ansible_host=192.168.10.1 api-username="john.smith" api-password="password1234" api_url="http://192.168.10.1" api_port="8697"

Command:
ansible-playbook -i hosts.yml vmware_desktop.yml -vvv

[john]% ansible-playbook -i hosts.yml vmware_desktop.yml -vvv
ansible-playbook 2.10.7
config file = /etc/ansible/ansible.cfg
configured module search path = ['/Users/john/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ansible
executable location = /Library/Frameworks/Python.framework/Versions/3.8/bin/ansible-playbook
python version = 3.8.2 (v3.8.2:7b3ab5921f, Feb 24 2020, 17:52:18) [Clang 6.0 (clang-600.0.57)]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /Volumes/Dropbox/Ansible/VMWare/hosts.yml as it did not pass its verify_file() method
Parsed /Volumes/Dropbox/Ansible/VMWare/hosts.yml inventory source with ini plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

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

PLAY [my_vmware_pro] ****************************************************************************************************************************************************************************************************************************************************************************************************
META: ran handlers

TASK [List all VMs] *****************************************************************************************************************************************************************************************************************************************************************************************************
task path: /Volumes/Dropbox/Ansible/VMWare/vmware_desktop.yml:8
<192.168.10.1> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.10.1> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/Users/john/.ansible/cp/82c0ac9e26 192.168.10.1 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<192.168.10.1> (255, b'', b'ssh: connect to host 192.168.10.1 port 22: Operation timed out\r\n')
fatal: [my_vmware_pro]: UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: connect to host 192.168.10.1 port 22: Operation timed out",
"unreachable": true
}

PLAY RECAP **************************************************************************************************************************************************************************************************************************************************************************************************************
my_vmware_pro : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0

MODULE FAILURE\nSee stdout/stderr for the exact error

[john]% ansible-playbook -i hosts.yml vmware_desktop.yml -vvv -M ./modules
ansible-playbook 2.10.7
config file = /etc/ansible/ansible.cfg
configured module search path = ['/Users/john/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ansible
executable location = /Library/Frameworks/Python.framework/Versions/3.8/bin/ansible-playbook
python version = 3.8.2 (v3.8.2:7b3ab5921f, Feb 24 2020, 17:52:18) [Clang 6.0 (clang-600.0.57)]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /Volumes/Dropbox/Ansible/VMWare/hosts.yml as it did not pass its verify_file() method
Parsed /Volumes/Dropbox/Ansible/VMWare/hosts.yml inventory source with ini plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

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

PLAY [my_vmware_pro] ****************************************************************************************************************************************************************************************************************************************************************************************************
META: ran handlers

TASK [List all VMs] *****************************************************************************************************************************************************************************************************************************************************************************************************
task path: /Volumes/Dropbox/Ansible/VMWare/vmware_desktop.yml:8
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: john
<127.0.0.1> EXEC /bin/sh -c 'echo ~john && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "echo /Users/john/.ansible/tmp"&& mkdir "echo /Users/john/.ansible/tmp/ansible-tmp-1624978848.1419132-5504-211548254995158" && echo ansible-tmp-1624978848.1419132-5504-211548254995158="echo /Users/john/.ansible/tmp/ansible-tmp-1624978848.1419132-5504-211548254995158" ) && sleep 0'
Using module file /Users/john/.ansible/collections/ansible_collections/qsypoq/vmware_desktop/plugins/modules/win_vmware_desktop_vminfos.py
<127.0.0.1> PUT /Users/john/.ansible/tmp/ansible-local-5499fkq0_mfh/tmp2melr67b TO /Users/john/.ansible/tmp/ansible-tmp-1624978848.1419132-5504-211548254995158/AnsiballZ_win_vmware_desktop_vminfos.py
<127.0.0.1> PUT /Users/john/.ansible/tmp/ansible-local-5499fkq0_mfh/tmpzywbxi1f TO /Users/john/.ansible/tmp/ansible-tmp-1624978848.1419132-5504-211548254995158/args
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /Users/john/.ansible/tmp/ansible-tmp-1624978848.1419132-5504-211548254995158/ /Users/john/.ansible/tmp/ansible-tmp-1624978848.1419132-5504-211548254995158/AnsiballZ_win_vmware_desktop_vminfos.py /Users/john/.ansible/tmp/ansible-tmp-1624978848.1419132-5504-211548254995158/args && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/Library/Frameworks/Python.framework/Versions/3.8/bin/python3 /Users/john/.ansible/tmp/ansible-tmp-1624978848.1419132-5504-211548254995158/AnsiballZ_win_vmware_desktop_vminfos.py /Users/john/.ansible/tmp/ansible-tmp-1624978848.1419132-5504-211548254995158/args && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /Users/john/.ansible/tmp/ansible-tmp-1624978848.1419132-5504-211548254995158/ > /dev/null 2>&1 && sleep 0'
fatal: [my_vmware_pro]: FAILED! => {
"changed": false,
"module_stderr": "",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 0
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.