ansible

Ansible, Windows and PowerShell: the Basics – Part 7, Utilising PowerShell DSC

In Part 7 of this series we’ll continue our journey with Ansible, Windows and PowerShell and look at how utilise PowerShell DSC. If you or your team already own some automation created using PowerShell DSC then it is possible to re-use that via an Ansible Playbook. Or maybe you think that you or they would prefer to create configuration automation going forward using a perhaps more familiar PowerShell DSC, then this could be a solution for you.

Ansible, Windows and PowerShell: the Basics – Part 6, Displaying Output from PowerShell Code

In Part 6 of this series we’ll continue our journey with Ansible, Windows and PowerShell and look at how we can display output from code in PowerShell scripts back in Ansible to help track the progress of a task. The following example will demonstrate how to send log info from a PowerShell script back to Ansible. Our job template in AWX is _5_log-output The contents of _5_log-output.yml are are follows:

Ansible, Windows and PowerShell: the Basics – Part 5, Example PowerShell Error Handling

In Part 5 of this series we’ll continue our journey with Ansible, Windows and PowerShell and look at how we can lay out code in PowerShell scripts in order to return error codes to Ansible to determine the success or failure of a task. In my experience different automation and orchestration toolsets can require you to return errors from PowerShell scripts in different ways. So far with Ansible I have found that returning an exit code of 0 (success) or 1 (failure) from the PowerShell script to Ansible will result in the success or failure of that task in the Playbook.

Ansible, Windows and PowerShell: the Basics – Part 4, Invoking PowerShell Code

In Part 4 of this series we’ll continue our journey with Ansible, Windows and PowerShell and look at how we can use Ansible to invoke PowerShell code directly. Our job template in AWX to test out the possible different scenarios is _3_invoke-powershell The contents of _3_invoke-powershell.yml are are follows: There are three main options we can take for approaching invoking PowerShell code, all using the win_shell module in some form.

Ansible, Windows and PowerShell: the Basics – Part 3, Windows Roles and Features

In Part 3 of this series we’ll continue our journey with Ansible, Windows and PowerShell and look at how we can use Ansible to prepare servers with Windows Roles and Features. The PowerShell story around support for Windows Roles and Features can be a little confusing, since there are two different sets of PowerShell cmdlets as well as the cmdline tools dism.exe and pkgmgr.exe. So knowing which tool to use to start with requires some effort itself.

Ansible, Windows and PowerShell: the Basics - Part 2, Install PowerShell Modules

In Part 2 of this series we’ll move on from the introductory topics and look at how we can use Ansible to prepare servers with any external PowerShell Modules they need from the PowerShell Gallery. Our job template in AWX is _1_install-psmodule The contents of _1_install-psmodule.yml are are follows: We can use the native Ansible module win_psmodule to do the work for us. In addition, we can ensure multiple modules are installed without needing a separate task for each one by looping using with_items.

Ansible, Windows and PowerShell: the Basics - Part 1, Windows Services

In Part 1 of this series we’ll warm up by taking a look at the lab setup I am using, configuring some basics in AWX and what’s possible with the Ansible win_service module to configure Windows services. Lab details: For Ansible, I’m using AWX deployed in containers based from the example documented here. Additionally, I have two Windows 2016 VMs. One to provide some basic Windows services such as DNS and Active Directory.

Ansible, Windows and PowerShell: the Basics - Introduction

Back in June of this year I presented a session at PowerShell Southampton on using Ansible and PowerShell together. There was a fair amount of interest in this topic both at the event and online afterwards, so I decided to follow it up here with a series of posts looking at the basics for someone getting started with Ansible. In particular using it to automate and configure Windows, where to use PowerShell for that task and sometimes where not to if there is native functionality already available within Ansible.

Running PowerShell Core Commands in a Linux Target from Ansible

Ansible has modules shell, for executing commands against Linux targets, and win_shell for executing commands against Windows targets - typically using PowerShell. So I was curious to see if it was possible to execute commands in a Linux target using PowerShell Core and if so, how to do it. For my test I have an Ubuntu 18.04 VM with PowerShell 7.3.5 installed: The shell module has an executable parameter described as “Change the shell used to execute the command.

Returning Data from PowerShell Scripts to be consumed by Ansible Playbooks

This topic was not initially obvious to me, so hopefully it will help someone out reading this. Consider the scenario where you have an Ansible playbook which executes some PowerShell code via win_shell and you wish to consume the PowerShell output later on in the playbook. The output from win_shell is available in the return value stdout (The command standard output ) or stdout_lines (The command standard output split in lines ).