The annoying task of sending a string variable with a space in AWX / Ansible Tower. How to avoid getting YAML’d!

Leave it up to windows to make standard Paths, Group names, OU’s with spaces in them. I had a troublesome task of trying to getting text string variables with spaces in them and getting this through AWX. If you are encountering the same issue, this article is for you.

What I found was that there is a particularly way you have to go about it. YAML can be a very unforgiving format sometimes. This is where can be unusually annoying. So in my problem I was getting a variable from AWX that had a space in it and surrounding quotes, then passing through YAML to the Playbook, which ultimately calls a powershell script feeding a parameter that contained the quotes in the command line.

Below is a snippet of the relevant code. This playbook code as an example is adding a Domain AD Group to a Local Group on the Server/Computer.

????win_shell:?powershell.exe?-Command?'C:\somepath\git\AD-automation\AD-Add-AD-Group-to-Local-Group.ps1?"{{?vm_name?}}{{?windows_ad_access_local_group_role?}} {{?domain_ad_group?}}"'

You might think that. Well I have my jinja in quotes and I should be good to go, or I dont need anything in my AWX prompt or var.- WRONG.


There are two main things that seemed to do the trick – they are.

  1. If you are using the Prompt in AWX or Ansible Tower – You MUST use Single Quotes ( ‘ )around your string that has a space. Double quotes ( ” ) in my exmaple turned out bad because of the way the string transfered from Ansible down to my Powershell Command. The Proper Way to Type it in the AWX console is: ‘Power Users’
  2. Make Sure your code has super explicit markers in your playbook for your variables ‘”{{ your_var }}”‘ The changes to my code that ended up working is below. This is a trick that I had to find going through a couple of searches to find. I hope this helps someone