Here are some further tips for people reading

* Use the yaml syntax when writting task rather than the key=value format, 
this makes it a lot simpler to write Windows paths.

e.g for the first task do.

- name: Copy a windows file from control node to remote node
  win_copy:
    src: /etc/ansible/winFiles/getFileVersion.exe
    dest: C:\Temp\

* Use backslashes for the Windows paths, if you use the yaml syntax, you 
only need to escape them when using double quote ""

e.g all of the below lead to the same value.

- some_module:
    path: C:\temp
    quoted_path: 'C:\temp'
    double_quoted_path: "C:\\temp"

* Avoid using the raw module, use win_command or win_shell instead, you 
can't use become or environment variables with raw
    * Use win_command when you are running an executable, avoid using this 
when running shell commands like dir, del or PowerShell cmdlets like 
New-Item, Copy-Item and so on
    * Use win_shell when you are running shell commands or powershell 
cmdlets, avoid using this to run executables as you need to deal with shell 
escaping for complex arguments

* For tasks that give you an access is denied, use become to run it like it 
would locally (not experimental as of the 2.5 release)

# this does not work and leads to an access is denied error
- name: upgrade powershell
  win_chocoletey:
    name: poweshell
    state: latest

# when using become this is no longer an issue
- name: upgrade powershell
  win_chocolatey:
    name: powershell
    state: latest
  become: yes
  become_method: runas
  become_user: SYSTEM

* If there is not an Windows module to complete a task you are looking for, 
look to see if there is an DSC resource instead (PowerShell v5 or newer is 
required)

e.g. to manage Hyper-V you can use the DSC resource like so

- name: install Hyper-V DSC resource
  win_psmodule:
    name: xHyper-V
    state: present

- name: create Hyper-V VM
  win_dsc:
    resource_name: xVMHyperv  # the DSC module to use
    # the below parameters are all the DSC parameters to set
    Ensure: present
    Name: HyperVHost
    VhdPath: C:\temp\vm.vhd
    StartupMemory: 6291456000
    Generation: 2
    ProcessorCount: 2

There are numerous other things that are good to know but you are probably 
best looking at the new documentation for Windows here 
http://docs.ansible.com/ansible/devel/windows.html.

Thanks

Jordan

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/72c8d3b0-9794-450d-9b12-396949b78eb0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to