set_fact for Windows domain login

49 views
Skip to first unread message

Mike Fennemore

unread,
Jun 7, 2016, 9:14:52 AM6/7/16
to Ansible Project
I have a specific use that requires the Domain\User Windows format.
My assumption was
- set_fact:
        my_login: "{{ ansible_env['USERDOMAIN'] }}\{{ ansible_env['USERNAME'] }}"

This doesn't seem to work however. How do I combine the two envrionmental variable with a \ between them?

J Hawkesworth

unread,
Jun 7, 2016, 9:23:44 AM6/7/16
to Ansible Project
When you are inside double quotes, you usually need double backslashes.  I've not used the ansible_env syntax but hopefully the following should do the trick.

- set_fact:
        my_login: "{{ ansible_env['USERDOMAIN'] }}\\{{ ansible_env['USERNAME'] }}"

Hope this helps,

Jon

Mike Fennemore

unread,
Jun 7, 2016, 9:31:02 AM6/7/16
to Ansible Project
Hi Jon, good call on the \\ , it does now set the fact. However if I run a debug I see it is now set as domain\\user.

J Hawkesworth

unread,
Jun 7, 2016, 9:41:55 AM6/7/16
to Ansible Project
Not tried, but worth trying single quotes and a single backslash

Christoph Wegener

unread,
Jun 7, 2016, 9:50:32 AM6/7/16
to Ansible Project
Just a guess - but wouldn't debug use python pprint and hence why you see \\ in debug?

Christoph Wegener

unread,
Jun 7, 2016, 10:00:49 AM6/7/16
to Ansible Project
I just had a quick look, all log output in ansible is done via python Logger objects. So, I'm not sure if the \\ is actually the representation of you data structure of if the \\ is a result of outputting the data structure via debug.
Reply all
Reply to author
Forward
0 new messages