# How to use user vars or unset default ones

**URL:** <https://forum.ansible.com/t/how-to-use-user-vars-or-unset-default-ones/18473>\
**Category:** Ansible Project\
**Created:** [June 11, 2015, 2:33pm UTC](https://forum.ansible.com/t/how-to-use-user-vars-or-unset-default-ones/18473 "2015-06-11T14:33:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan\_Garcia](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@Ivan\_Garcia](https://forum.ansible.com/u/Ivan_Garcia)\
**Post date:** [June 11, 2015, 2:33pm UTC](https://forum.ansible.com/t/how-to-use-user-vars-or-unset-default-ones/18473/1 "2015-06-11T14:33:43Z")

</div>

Hi all,

I’m working to automate some Tomcat deployments and I have a problem with the enconding. When I start the Tomcat, Ansible use its default LANG=C and LC\_TYPE=C variables and the application is not deployed properly, some characters doesn’t appear right.

Following you can see the PID info and notice that it’s putting the default variables instead of using the user variables (root as I’m using sudo):

# cat /proc/18107/environ

TOMCAT\_HOME=/opt/tomcatTERM=linuxSHELL=/bin/bashCATALINA\_HOME=/opt/tomcat TOMCAT\_START=/opt/tomcat/bin/startup.shUSER=tomcatJAVA\_OPTS=-server -Xms1024m -Xmx2048m -XX:PermSize=256m -XX:MaxPermSize=512m -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager JRE\_HOME=/op /java/latestSUDO\_USER=atlasSUDO\_UID=50000USERNAME=rootMAIL=/var/mail/at PATH=/sbin:/usr/sbin:/bin:/usr/binPWD=/opt/tomcat/webapps/simyoJAVA\_HOME=/opt/jav /latest LANG=CHOME=/home/tomcatSUDO\_COMMAND=/bin/sh -c echo SUDO-SUCCESS-bdoirfizidenadwclaoujhbewakdemoh; LANG=C LC\_CTYPE=C /usr/bin/python /home/at //.ansible/tmp/ansible-tmp-1434028812.49-238808986274644/command; rm -rf /home/atlas//.ansible/tmp/ansible-tmp-1434028812.49-238808986274644/ \>/dev/null 2\>&1SHLVL=5TOMCAT\_STOP=/opt/tomcat/bin/shutdown.shLOGNAME=tomcat LC\_CTYPE=CSUDO\_GID=50000\_=/opt/java/latest/bin/javaLD\_LIBRARY\_PATH=/opt/java/jdk1.6.0\_2 /jre/lib/i386/server: /opt/java/jdk1.6.0\_24/jre/lib/i386:/opt/java/jdk1.6.0\_24/jre/../lib/i386

Do you know if there’s any way to use the user variables instead of the “ansible\_env” vars? If not, there’s any way to unset this vars at playbook level?

I’ve seen this docu but there’s nothing about unset vars → [https://docs.ansible.com/playbooks\_environment.html](https://docs.ansible.com/playbooks_environment.html)

Cheers,

Ivan G.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 11, 2015, 2:45pm UTC](https://forum.ansible.com/t/how-to-use-user-vars-or-unset-default-ones/18473/2 "2015-06-11T14:45:09Z")

</div>

if you unset LC/LANG variables they default to C/POSIX, so i would  
actually set them to what you need.

---

<div class="post-metadata">

**Author:** ![Ivan\_Garcia](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@Ivan\_Garcia](https://forum.ansible.com/u/Ivan_Garcia)\
**Post date:** [June 11, 2015, 4:29pm UTC](https://forum.ansible.com/t/how-to-use-user-vars-or-unset-default-ones/18473/3 "2015-06-11T16:29:57Z")

</div>

Thanks for your answer Brian. Apart from that I’d really like to know if there’s a way to use the user’s variables of the user that is specified in the playbook. In my case I’m doing a sudo: yes.

Cheers,

Ivan

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 11, 2015, 4:37pm UTC](https://forum.ansible.com/t/how-to-use-user-vars-or-unset-default-ones/18473/4 "2015-06-11T16:37:20Z")

</div>

Yes and no, ansible avoids using a login shell, so vars defined for  
the user that rely on that won't be picked up. Sudo , by default, also  
removes most vars from the source user and can set it's own vars for  
the target user, it also does not normally pickup vars that depend on  
login to be set.

---

<div class="post-metadata">

**Author:** ![Ivan\_Garcia](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@Ivan\_Garcia](https://forum.ansible.com/u/Ivan_Garcia)\
**Post date:** [June 12, 2015, 2:20pm UTC](https://forum.ansible.com/t/how-to-use-user-vars-or-unset-default-ones/18473/5 "2015-06-12T14:20:31Z")

</div>

Brian thanks for your answers!

Cheers,

Ivan G.
