# set\_fact for Windows domain login

**URL:** <https://forum.ansible.com/t/set-fact-for-windows-domain-login/21687>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [June 7, 2016, 1:14pm UTC](https://forum.ansible.com/t/set-fact-for-windows-domain-login/21687 "2016-06-07T13:14:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Fennemore](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@Mike\_Fennemore](https://forum.ansible.com/u/Mike_Fennemore)\
**Post date:** [June 7, 2016, 1:14pm UTC](https://forum.ansible.com/t/set-fact-for-windows-domain-login/21687/1 "2016-06-07T13:14:52Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [June 7, 2016, 1:23pm UTC](https://forum.ansible.com/t/set-fact-for-windows-domain-login/21687/2 "2016-06-07T13:23:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mike\_Fennemore](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@Mike\_Fennemore](https://forum.ansible.com/u/Mike_Fennemore)\
**Post date:** [June 7, 2016, 1:31pm UTC](https://forum.ansible.com/t/set-fact-for-windows-domain-login/21687/3 "2016-06-07T13:31:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [June 7, 2016, 1:41pm UTC](https://forum.ansible.com/t/set-fact-for-windows-domain-login/21687/4 "2016-06-07T13:41:55Z")

</div>

Not tried, but worth trying single quotes and a single backslash

---

<div class="post-metadata">

**Author:** ![Christoph\_Wegener](https://avatars.discourse-cdn.com/v4/letter/c/57b2e6/32.png) [@Christoph\_Wegener](https://forum.ansible.com/u/Christoph_Wegener)\
**Post date:** [June 7, 2016, 1:50pm UTC](https://forum.ansible.com/t/set-fact-for-windows-domain-login/21687/5 "2016-06-07T13:50:32Z")

</div>

Just a guess - but wouldn’t debug use python pprint and hence why you see \ in debug?

---

<div class="post-metadata">

**Author:** ![Christoph\_Wegener](https://avatars.discourse-cdn.com/v4/letter/c/57b2e6/32.png) [@Christoph\_Wegener](https://forum.ansible.com/u/Christoph_Wegener)\
**Post date:** [June 7, 2016, 2:00pm UTC](https://forum.ansible.com/t/set-fact-for-windows-domain-login/21687/6 "2016-06-07T14:00:48Z")

</div>

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.
