I am new to ansible, what is best approach , is it to use ansible’s windows modules for all the things or writing powershell scripts and running that powershell script in all servers through ansible. For example: i have a flow
- Download files from an url
- Extract if it is zip
- Deploy in IIS
We can do this easily in powershell, only thing we cannot do in powershell is to install the scripts from a centralised server, but ansible does that. So what could be best approach for this?
Well you can use ansible as a way of delivering and running powershell scripts and if that’s all you need to do, that’s fine.
However I think its worth making use of modules and roles and templates and group vars and filters and ‘doing stuff the ansible way’ as once you have deployment sorted out, there’s maintenance and running updates and all manner of other activities that can make use of your modules and roles.
Modules and playbooks can be more readable than raw powershell scripts so if you need to have deployment plans, playbooks can be a good way to communicate with people who aren’t comfortable with a lot of code too.
Ultimately it depends on what you are optimising for.
Incidentally you can do all the steps below without any powershell if you want using something like the below (untested). If you can arrange things so the build contains a version number, you could also uncommente the ‘creates’ line and make the playbook pretty much idempotent, making it safe to re-run and
playbook: deploy build to iis
{{build_file}} would contain the file name of your built application. You could pass into the playbook using -e extra_vars command line, or pick up from an included file.
Intersting, but i am still new to ansible, will take some more days to get used to it… What does creates do?
It tells the module that what the expected outcome of making the desired change is, so if the file is present, the module ‘knows’ it doesn’t need to make any further changes.
If you make all your tasks work like this, you can re-run your playbooks in the knowledge that they will only make changes that haven’t already been made. This speeds things up and eventually sort of pulls your machines into the state described by your playbooks. Read up on ‘idempotency’ and ‘desired state’ for a wider discussion of this idea and how it can be useful.
All the best,
Jon