tl;dr I’m curious how people are developing windows modules and specifically details about their workflow.
Context: I have been leading the Ansible push in my organization and have recently been getting the Windows teams on board. So far, due to time crunch and lack of experience, our devs have been writing basic powershell scripts (windows modules used when applicable). We now have a little more time though, and I am starting to figure out the best workflow to pass along to the windows devs for transitioning some scripts to modules.
My initial brainstorm:
company ansible repo with vagrant file for basic local VM with a shared folder. (done)
playbook to configure the vagrant vm as an “ansible-hq” server. I use the same playbook in production for our control server. (done)
windows devs work on modules and save them to the shared folder
vagrant ssh and ~/ansible/hacking/test-module -m /shared/test_module.ps1
rinse and repeat
It doesn’t look like the test-module command works with powershell modules (this may be obvious), even on existing core win_modules (e.g. win_msi), I got the following output:
`
including generated source, if any, saving to: /home/jpherold/.ansible_module_generated
this may offset any line numbers in tracebacks/debuggers!
Currently I work stuff up locally using ISE, IDLE and notepad++ (for yaml syntax highlighting) then push changes into our source code repo.
To test stuff, pull and update from source code repo
set
ANSIBLE_KEEP_REMOTE_FILES=1
and run against vms, making liberal use of reverting to a baseline snapshot.
Keep remote files lets you see the full powershell for the module and re-run on the target vm.
I follow a similar workflow as jhawkesworth. I usually write the powershell first using notepad++ or similar, get that working on a local windows test box (that can be reverted to a snapshot as needed), and then wrap it in the ansible json parsing etc inside a feature branch off of the ansible-dev branch. Finally write some unit/integration tests and run them with commands similar to:
TEST_FLAGS=“-t tag_name -i /etc/ansible/hosts” make playbook
test_winrm contains a lot of the other windows tests.