regex_replace returning '\u0001'

$ ansible-playbook --version
ansible-playbook 1.8 (devel 1d3a8bd39c) last updated 2014/09/18 10:33:54 (GMT -400)

Hello! This is driving me bonkers . . . can anyone see what I’m doing wrong here?

Setting a var, which is fine:

  • name: Get VBox version for installing extension pack
    command: /usr/bin/VBoxManage --version
    register: vbox_ver

TASK: [workstation | debug msg={{ vbox_ver.stdout }}] *************************
ok: [localhost] => {
“msg”: “4.3.10_Ubuntur93012”
}

Then trying to set a fact based on that using regex_replace:

  • name: Set major/minor number of vbox release
    set_fact:
    vbox_ver_maj: “{{ vbox_ver.stdout | regex_replace(‘^(.)_.$’,‘\1’) }}”

which gives me:

TASK: [workstation | debug msg={{ vbox_ver_maj }}] ****************************
ok: [localhost] => {
“msg”: “\u0001”
}

when it should give me 4.3.10 . … any thoughts would be greatly appreciated!

Regards,
Guy

This happens when you do not have enough slashes. There are a different number of slashes needed for escape based on if you are using complex args (YAML) as opposed to args (key=value)

complex args: \\
args: \

So you need to increase your slashes to a total of 4

Soooooo much better. Thank you!!