The problem here is VirtualBox networking. The host can't directly reach
the guest so packer sets up a NAT port forwarding on a random port
restricted by ssh_host_port_min and max 1) (despite the naming this is also
used for WinRM). You need to set this port in your inventory file instead
of 55985. You can either parse this from the output of a VBoxManage
command, or set min and max to the same value, which in effect will
hardcode the port. You can also check the ansible (remote) provisioner 2)
which handles all of this for you (but it has been a bit tricky on certain
ansible + packer versions for WinRM).


1) https://www.packer.io/docs/builders/virtualbox-iso.html#ssh_host_port_min
2) https://www.packer.io/docs/provisioners/ansible.html

On Sun, Oct 14, 2018 at 7:26 AM Rahamath Ulla <[email protected]> wrote:

> Hello,
> I am trying to achieve building windows servers with some packages [like
> installing webserver] using virtualbox and ansible.
>
> I am able to build minimum OS without ansible. But when I added ansible
> post provisioner, its failing. The problem is its unable to reach the newly
> built VM in virtualbox.
>
> Please share if you have successful in this kind of solution. I tried with
> removing inventory file section and allowed packer to create dynamically
> created host file. but still failed.
>
> Below is the packer section:
>   "builders": [
>     {
>       "type": "virtualbox-iso",
>       "iso_url": "{{user `iso_url`}}",
>       "guest_additions_mode": "attach",
>       "iso_checksum_type": "{{user `iso_checksum_type`}}",
>       "iso_checksum": "{{user `iso_checksum`}}",
>       "headless": false,
>       "shutdown_timeout": "15m",
>       "post_shutdown_delay": "5m",
>       "boot_wait": "2m",
>       "winrm_username": "vagrant",
>       "winrm_password": "vagrant",
>       "winrm_timeout": "6h",
>       "communicator": "winrm",
>       "shutdown_command": "shutdown /s /t 180 /f /d p:4:1 /c \"Packer
> Shutdown\"",
>       "guest_os_type": "Windows2012_64",
>       "disk_size": 61440,
>       "floppy_files": [
>         "{{user `autounattend`}}",
>         "./scripts/microsoft-updates.bat",
>         "./scripts/Boot-Strap.ps1",
>         "./scripts/configansible.ps1",
>         "./scripts/createla.bat"
>       ],
>       "vboxmanage": [
>         [
>           "modifyvm",
>           "{{.Name}}",
>           "--memory",
>           "2048"
>         ],
>         [
>           "modifyvm",
>           "{{.Name}}",
>           "--cpus",
>           "2"
>         ]
>       ]
>     }
>   ],
>
>   "provisioners": [
>     {
>       "type": "shell-local",
>       "command": "ansible-playbook webservers.yml -vvvv"
>     }
> ],
>
>
> ================================================================================
> ansible.cfg:
> [defaults]
> log_path=/home/vagrant/packer/logfile
> inventory=/home/vagrant/packer/hosts
> ==========================================
>
> hosts:
> [webservers]
> 127.0.0.1
>
>
> [webservers:vars]
> ansible_user=vagrant
> ansible_password=vagrant
> ansible_port=55985
> ansible_connection=winrm
> ansible_winrm_server_cert_validation=ignore
> =========================================
> group_vars:
> ---
> ansible_ssh_user: vagrant
> ansible_ssh_pass: vagrant
> ansible_ssh_port: 55985
> ansible_connection: winrm
> ansible_winrm_server_cert_validation: ignore
> =====================================
>
> ansible playbook:
> ---
> - hosts: webservers
>   roles:
>     - webservers
> =====================================================
> Error message in packer output:
> ==> virtualbox-iso: Executing local command: ansible-playbook
> webservers.yml -vvvv
>     virtualbox-iso: Using /home/vagrant/packer/ansible.cfg as config file
>     virtualbox-iso: statically included:
> /home/vagrant/packer/roles/webservers/tasks/install.yml
>     virtualbox-iso: Loading callback plugin default of type stdout, v2.0
> from
> /usr/local/lib/python2.7/dist-packages/ansible/plugins/callback/__init__.pyc
>     virtualbox-iso:
>     virtualbox-iso: PLAYBOOK: webservers.yml
> *******************************************************
>     virtualbox-iso: 1 plays in webservers.yml
>     virtualbox-iso:
>     virtualbox-iso: PLAY [webservers]
> **************************************************************
>     virtualbox-iso:
>     virtualbox-iso: TASK [setup]
> *******************************************************************
>     virtualbox-iso: Using module file
> /usr/local/lib/python2.7/dist-packages/ansible/modules/core/windows/setup.ps1
>     virtualbox-iso: <127.0.0.1> ESTABLISH WINRM CONNECTION FOR USER:
> vagrant on PORT 55985 TO 127.0.0.1
>     virtualbox-iso: fatal: [127.0.0.1]: UNREACHABLE! => {
>     virtualbox-iso: "changed": false,
>     virtualbox-iso: "msg": "ssl: HTTPSConnectionPool(host='127.0.0.1',
> port=55985): Max retries exceeded with url: /wsman (Caused by
> NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at
> 0x7f67097e7a90>: Failed to establish a new connection: [Errno 111]
> Connection refused',))",
>     virtualbox-iso: "unreachable": true
>     virtualbox-iso: }
>     virtualbox-iso: to retry, use: --limit
> @/home/vagrant/packer/webservers.retry
>     virtualbox-iso:
>     virtualbox-iso: PLAY RECAP
> *********************************************************************
>     virtualbox-iso: 127.0.0.1                  : ok=0    changed=0
> unreachable=1    failed=0
>     virtualbox-iso:
> ===========================================================
>
> --
> This mailing list is governed under the HashiCorp Community Guidelines -
> https://www.hashicorp.com/community-guidelines.html. Behavior in
> violation of those guidelines may result in your removal from this mailing
> list.
>
> GitHub Issues: https://github.com/mitchellh/packer/issues
> IRC: #packer-tool on Freenode
> ---
> You received this message because you are subscribed to the Google Groups
> "Packer" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/packer-tool/3f2ec36e-99c0-4349-a8b0-22ce801d4825%40googlegroups.com
> <https://groups.google.com/d/msgid/packer-tool/3f2ec36e-99c0-4349-a8b0-22ce801d4825%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
This mailing list is governed under the HashiCorp Community Guidelines - 
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of 
those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
--- 
You received this message because you are subscribed to the Google Groups 
"Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/packer-tool/CALz9Rt9zQcqmeKGr%2BK9w7otuQSo85U4_-pJbq7ward71jpAb3g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to