From 0c6e6ba637fe9454dd20f046170158c3e4873bce Mon Sep 17 00:00:00 2001 From: Adam Robinson Date: Tue, 3 Jul 2018 11:12:12 -0400 Subject: [PATCH] Update Ansible provisioner docs for WinRM --- .../source/docs/provisioners/ansible.html.md | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/website/source/docs/provisioners/ansible.html.md b/website/source/docs/provisioners/ansible.html.md index cac00ab60..82047070d 100644 --- a/website/source/docs/provisioners/ansible.html.md +++ b/website/source/docs/provisioners/ansible.html.md @@ -192,7 +192,8 @@ Building within a chroot (e.g. `amazon-chroot`) requires changing the Ansible co ### winrm communicator -Windows builds require a custom Ansible connection plugin and a particular configuration. Assuming a directory named `connection_plugins` is next to the playbook and contains a file named `packer.py` whose contents is +Windows builds require a custom Ansible connection plugin and a particular configuration. Assuming a directory named `connection_plugins` is next to the playbook and contains a file named `packer.py` which implements +the connection plugin. On versions of Ansible before 2.4.x, the following works as the connection plugin ``` python from __future__ import (absolute_import, division, print_function) @@ -213,6 +214,43 @@ class Connection(SSHConnection): super(Connection, self).__init__(*args, **kwargs) ``` +Newer versions of Ansible require all plugins to have a documentation string. You will need to copy +the `options` from the `DOCUMENTATION` string from the [ssh.py Ansible connection plugin](https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/ssh.py) +of the Ansible version you are using and add it to packer.py similar to as follows + +``` python +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from ansible.plugins.connection.ssh import Connection as SSHConnection + +DOCUMENTATION = ''' + connection: packer + short_description: ssh based connections for powershell via packer + description: + - This connection plugin allows ansible to communicate to the target packer + machines via ssh based connections for powershell. + author: Packer + version_added: na + options: + **** Copy the options from + https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/ssh.py + for the version of Ansible you are using **** +''' + +class Connection(SSHConnection): + ''' ssh based connections for powershell via packer''' + + transport = 'packer' + has_pipelining = True + become_methods = [] + allow_executable = False + module_implementation_preferences = ('.ps1', '') + + def __init__(self, *args, **kwargs): + super(Connection, self).__init__(*args, **kwargs) +``` + This template should build a Windows Server 2012 image on Google Cloud Platform: ``` json