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

Can not build Windows by Packer using Qemu + Ansible + WinRM #4773

Closed
ruzickap opened this Issue Apr 6, 2017 · 5 comments

Comments

Projects
None yet
4 participants
@ruzickap
Contributor

ruzickap commented Apr 6, 2017

I'm trying to build the Windows Server 2016 using Qemu + Ansible + WinRM. I would like to use Ansible for windows configuration by using winrm like it's described here: https://www.packer.io/docs/provisioners/ansible.html

I do have the packer.py installed in the ~/.ansible/plugins/connection_plugins/ directory and configured in ~/.ansible.cfg:

$ grep connection_plugins ~/.ansible.cfg
connection_plugins = ~/.ansible/plugins/connection_plugins/:/usr/share/ansible_plugins/connection_plugins
$ ls -la ~/.ansible/plugins/connection_plugins/packer.py
-rw-rw-r-- 1 ruzickap ruzickap 511 Apr  6 11:32 /home/ruzickap/.ansible/plugins/connection_plugins/packer.py

The WinRM is enabled when Windows Server (by running Autounattend.xml https://gist.github.com/ruzickap/8d5d96fbc24cda80a0ff2fc0c9b8835e) is installed and packer can use it. When the provisioning part started - ansible can not use WinRM properly and I got the error (see the log).

Simple ansible playbook "win.yml":

---
- hosts: all
  gather_facts: no

  tasks:
    - name: Start NTP service (w32time)
      win_service:
        name: w32time
        state: started

    - name: Configure NTP
      raw: w32tm /config /manualpeerlist:"ntp.cesnet.cz" /reliable:yes /update

    - name: Enable Remote Desktop
      raw: set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'-name "fDenyTSConnections" -Value 0

    - name: Allow connections from computers running any version of Remote Desktop (less secure)
      win_regedit:
        key: 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp'
        value: UserAuthentication
        data: 0
        datatype: dword

    - name: Allow RDP traffic
      raw: Enable-NetFirewallRule -DisplayGroup "Remote Desktop"

Packer template "windows-server-2016-eval-ansible.json":

{
  "builders":
  [
    {
      "name": "windows-server-2016-eval",
      "type": "qemu",
      "iso_checksum_type": "sha256",
      "iso_checksum": "1ce702a578a3cb1ac3d14873980838590f06d5b7101c5daaccbac9d73f1fb50f",
      "iso_urls": [ "http://care.dlservice.microsoft.com/dl/download/1/4/9/149D5452-9B29-4274-B6B3-5361DBDA30BC/14393.0.161119-1705.RS1_REFRESH_SERVER_EVAL_X64FRE_EN-US.ISO" ],
      "communicator": "winrm",
      "winrm_username": "Administrator",
      "winrm_password": "vagrant",
      "winrm_timeout": "12h",
      "winrm_use_ssl": "true",
      "winrm_insecure": "true",

      "qemuargs": [[ "-display", "gtk" ], [ "-m", "4G" ], [ "-smp", 2 ]],
      "disk_size": "51200",

      "disk_interface": "ide",
      "net_device": "e1000",

      "floppy_files": [
        "Autounattend.xml"
      ]
    }
  ],
  "provisioners": [
    {
      "type": "ansible",
      "user": "vagrant",
      "playbook_file": "win.yml",
      "extra_arguments": [
        "--connection", "packer",
        "--extra-vars", "ansible_shell_type=powershell ansible_shell_executable=None",
        "-vvv"
      ]
    }
  ],
  "post-processors": [
    [
      {
        "type": "vagrant",
        "output": "{{ user `name` }}-{{.Provider}}.box"
      }
    ]
  ]
}
@mwhooker

This comment has been minimized.

Show comment
Hide comment
@mwhooker

mwhooker Apr 6, 2017

Collaborator

Thanks for the report, @ruzickap. If you don't get any help here, you might have better luck sending an email to the mailing list. People who look at the github issues tend to be most helpful when it comes to bugs in the source code

Collaborator

mwhooker commented Apr 6, 2017

Thanks for the report, @ruzickap. If you don't get any help here, you might have better luck sending an email to the mailing list. People who look at the github issues tend to be most helpful when it comes to bugs in the source code

@andmos

This comment has been minimized.

Show comment
Hide comment
@andmos

andmos Jun 1, 2017

@ruzickap have you come any way with this? I am looking to do something similar with Server 2012 on a CentOS build server, would be nice to know if I only have trouble in front of me..

andmos commented Jun 1, 2017

@ruzickap have you come any way with this? I am looking to do something similar with Server 2012 on a CentOS build server, would be nice to know if I only have trouble in front of me..

@ruzickap

This comment has been minimized.

Show comment
Hide comment
@ruzickap

ruzickap Jun 1, 2017

Contributor

I'm sorry, but I have never seen packer configuration files + ansible playbooks which I can deploy windows machine using Qemu + Ansible + WinRM.
I hope somebody will describe it properly one day (or packer will support it - like it's in the documentation)...

Contributor

ruzickap commented Jun 1, 2017

I'm sorry, but I have never seen packer configuration files + ansible playbooks which I can deploy windows machine using Qemu + Ansible + WinRM.
I hope somebody will describe it properly one day (or packer will support it - like it's in the documentation)...

@rickard-von-essen

This comment has been minimized.

Show comment
Hide comment
@rickard-von-essen

rickard-von-essen Jun 1, 2017

Collaborator

From the logs it looks like the template in the original post works fine except that it fails on some ansible task. If you edit the playbook to just have the first task and run doesn't it work then?

Collaborator

rickard-von-essen commented Jun 1, 2017

From the logs it looks like the template in the original post works fine except that it fails on some ansible task. If you edit the playbook to just have the first task and run doesn't it work then?

@ruzickap

This comment has been minimized.

Show comment
Hide comment
@ruzickap

ruzickap Oct 7, 2017

Contributor

Hello guys.

I just tested it with Ansible 2.4 and the bug was fixed.

Closing the issue...

Contributor

ruzickap commented Oct 7, 2017

Hello guys.

I just tested it with Ansible 2.4 and the bug was fixed.

Closing the issue...

@ruzickap ruzickap closed this Oct 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment