How to use user vars or unset default ones

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

Cheers,

Ivan G.

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

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

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.

Brian thanks for your answers!

Cheers,

Ivan G.