molecule-vagrant
molecule-vagrant copied to clipboard
Molecule doesn't work well with WSL2
My environment: W10 laptop WSL2, Ubuntu 20, molecule 3.0.8 molecule-vagrant 0.3
I can create win2019 VM in virtualbox via Molecule create, but can't reach VM after creation and configure winrm. I can run small ansible-playbook to reach from Ubuntu 20 to win2019 VM and create folder. ssh [email protected] -p 2222 is working too. but got follow error message.
` ansible-playbook 2.9.12 config file = /home/silver/.cache/molecule/ansible-role-example-role/default/ansible.cfg configured module search path = ['/home/silver/virtualenvs/windowslob/lib/python3.8/site-packages/molecule/provisioner/ansible/plugins/modules', '/home/silver/virtualenvs/windowslob/lib/python3.8/site-packages/molecule_vagrant/modules', '/home/silver/.cache/molecule/ansible-role-example-role/default/library', '/home/silver/projects/winlob/ansible-role-example-role/library', '/home/silver/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/silver/virtualenvs/windowslob/lib/python3.8/site-packages/ansible executable location = /home/silver/virtualenvs/windowslob/bin/ansible-playbook python version = 3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0] Using /home/silver/.cache/molecule/ansible-role-example-role/default/ansible.cfg as config file host_list declined parsing /home/silver/.cache/molecule/ansible-role-example-role/default/inventory/ansible_inventory.yml as it did not pass its verify_file() method script declined parsing /home/silver/.cache/molecule/ansible-role-example-role/default/inventory/ansible_inventory.yml as it did not pass its verify_file() method Parsed /home/silver/.cache/molecule/ansible-role-example-role/default/inventory/ansible_inventory.yml inventory source with yaml plugin
PLAYBOOK: create.yml ***********************************************************
1 plays in /home/silver/virtualenvs/windowslob/lib/python3.8/site-packages/molecule_vagrant/playbooks/create.yml
PLAY [Create] ******************************************************************
META: ran handlers
TASK [Create molecule instance(s)] *********************************************
task path: /home/silver/virtualenvs/windowslob/lib/python3.8/site-packages/molecule_vagrant/playbooks/create.yml:8
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: silver
<127.0.0.1> EXEC /bin/sh -c 'echo ~silver && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/silver/.ansible/tmp `"&& mkdir "` echo /home/silver/.ansible/tmp/ansible-tmp-1637589341.9568806-7136-272674182548617 `" && echo ansible-tmp-1637589341.9568806-7136-272674182548617="` echo /home/silver/.ansible/tmp/ansible-tmp-1637589341.9568806-7136-272674182548617 `" ) && sleep 0'
Using module file /home/silver/virtualenvs/windowslob/lib/python3.8/site-packages/molecule_vagrant/modules/vagrant.py
<127.0.0.1> PUT /home/silver/.ansible/tmp/ansible-local-7118jw9hxuus/tmp1g6rs7_7 TO /home/silver/.ansible/tmp/ansible-tmp-1637589341.9568806-7136-272674182548617/AnsiballZ_vagrant.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/silver/.ansible/tmp/ansible-tmp-1637589341.9568806-7136-272674182548617/ /home/silver/.ansible/tmp/ansible-tmp-1637589341.9568806-7136-272674182548617/AnsiballZ_vagrant.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/home/silver/virtualenvs/windowslob/bin/python /home/silver/.ansible/tmp/ansible-tmp-1637589341.9568806-7136-272674182548617/AnsiballZ_vagrant.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/silver/.ansible/tmp/ansible-tmp-1637589341.9568806-7136-272674182548617/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/home/silver/.ansible/tmp/ansible-tmp-1637589341.9568806-7136-272674182548617/AnsiballZ_vagrant.py", line 102, in <module>
_ansiballz_main()
File "/home/silver/.ansible/tmp/ansible-tmp-1637589341.9568806-7136-272674182548617/AnsiballZ_vagrant.py", line 94, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/silver/.ansible/tmp/ansible-tmp-1637589341.9568806-7136-272674182548617/AnsiballZ_vagrant.py", line 40, in invoke_module
runpy.run_module(mod_name='ansible.modules.vagrant', init_globals=None, run_name='__main__', alter_sys=True)
File "/usr/lib/python3.8/runpy.py", line 207, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib/python3.8/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/tmp/ansible_vagrant_payload_2_l4b3f2/ansible_vagrant_payload.zip/ansible/modules/vagrant.py", line 632, in <module>
File "/tmp/ansible_vagrant_payload_2_l4b3f2/ansible_vagrant_payload.zip/ansible/modules/vagrant.py", line 628, in main
AttributeError: 'AnsibleModule' object has no attribute 'result'
failed: [localhost] (item=ansible-role-example-role-windows-2019) => {
"ansible_loop_var": "item",
"changed": false,
"item": {
"box": "jborean93/WindowsServer2019",
"config_options": {
"vm.communicator": "'winrm'",
"winrm.password": "'vagrant'",
"winrm.remote_user": "'vagrant'"
},
"cpus": 1,
"groups": [
"windows"
],
"interfaces": [
{
"auto_correct": true,
"guest": 22,
"host": 2222,
"host_ip": "192.168.0.38",
"network_name": "forwarded_port"
}
],
"memory": 1024,
"name": "ansible-role-example-role-windows-2019",
"provision": true,
"state": "up"
},
"module_stderr": "Traceback (most recent call last):\n File \"/home/silver/.ansible/tmp/ansible-tmp-1637589341.9568806-7136-272674182548617/AnsiballZ_vagrant.py\", line 102, in <module>\n _ansiballz_main()\n File \"/home/silver/.ansible/tmp/ansible-tmp-1637589341.9568806-7136-272674182548617/AnsiballZ_vagrant.py\", line 94, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/home/silver/.ansible/tmp/ansible-tmp-1637589341.9568806-7136-272674182548617/AnsiballZ_vagrant.py\", line 40, in invoke_module\n runpy.run_module(mod_name='ansible.modules.vagrant', init_globals=None, run_name='__main__', alter_sys=True)\n File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_vagrant_payload_2_l4b3f2/ansible_vagrant_payload.zip/ansible/modules/vagrant.py\", line 632, in <module>\n File \"/tmp/ansible_vagrant_payload_2_l4b3f2/ansible_vagrant_payload.zip/ansible/modules/vagrant.py\", line 628, in main\nAttributeError: 'AnsibleModule' object has no attribute 'result'\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}
PLAY RECAP *********************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
ERROR: `
Any ideas why Molecule can't reach win2019 VM in virtualbox?
The error handling from molecule-vagrant 0.3 is not so good, leading to a not very helpful message. Can you try git HEAD to see if you can get a better error message ? Moreover, be informed that winrm connection support is missing, as mentioned in https://github.com/ansible-community/molecule-vagrant/issues/98.
@apatard , I'm so sorry. I'm very new to molecule and others. How to git HEAD to see better error message?
Also, my colleagues working on Mac and they have no issues with Molecule + winrm , is this WSL 2 thing? (also I have trouble with WSL 1). Are you saying winrm connection is no good for molecule and win2019 and suggest to use ssh instead? I had a very brief time that when I switch Ansible connection with SSH and then after I tried few things and it's gone. I can't really reproduce SSH connection again. Are you suggesting I should use SSH on Molecule settings and Ansible settings and rebuild VM in virtualbox?
I've had similar issues with WSL2 and HyperV. For the they turned out to be related to the configuration of the virtual network switches created by Windows. I run a small snippet of PowerShell as a user with administrative rights in order to remedy this:
Get-NetIPInterface | where {$_.InterfaceAlias -eq 'vEthernet (WSL)' -or $_.InterfaceAlias -eq 'vEthernet (Default Switch)'} | Set-NetIPInterface -Forwarding Enable
These changes unfortunately are not permanent. I'm planning on creating a ScheduledTask I can trigger from WSL2 in order to make it permanent unless anybody has a better solution
I hope you solved this problem before and this is just for the next person stumbling over this.