Hey Gal's N Guy's,
Ansible isn't sourcing .bashrc or .bash_profile when running -m shell. But when I login via ssh, there isn't any issues. The shell PATH is set correctly in .bashrc and now also in .bash_profile . As usual /bin/sh points to bash .
Is there another option or a configuration to allow for this? This is a vanilla Ansible install on CentOS 7 .
--
Cheers,
Tom K.
-------------------------------------------------------------------------------------
Living on earth is expensive, but it includes a free trip around the sun.
[root@ans0101 ansible]# ansible -i inventory cm-r01nn01 -m shell -a "java -version" -become
cm-r01nn01 | FAILED | rc=127 >>
/bin/bash: java: command not foundnon-zero return code
[root@ans0101 ansible]# ssh cm-r01nn01
Last login: Sat Jun 2 09:15:25 2018 from 192.168.0.142
[root@cm-r01nn01 ~]# java -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
[root@cm-r01nn01 ~]# logout
Connection to cm-r01nn01 closed.
[root@ans0101 ansible]#
[root@ans0101 ansible]#
[root@ans0101 ansible]# ansible -i inventory cm-r01nn01 -m shell -a "source ~/.bashrc; java -version" -become
cm-r01nn01 | SUCCESS | rc=0 >>
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
[root@ans0101 ansible]# ansible -i inventory cm-r01nn01 -m shell -a 'java -version' -become
cm-r01nn01 | FAILED | rc=127 >>
/bin/bash: java: command not foundnon-zero return code
[root@ans0101 ansible]# ssh cm-r01nn01
Last login: Sat Jun 2 09:24:20 2018 from 192.168.0.142
[root@cm-r01nn01 ~]#
[root@cm-r01nn01 ~]#
[root@cm-r01nn01 ~]# logout
Connection to cm-r01nn01 closed.
[root@ans0101 ansible]#
[root@ans0101 ansible]#
[root@ans0101 ansible]# ansible -i inventory cm-r01nn01 -m shell -a 'echo export JAVA_HOME=//usr/java/jdk1.7.0_67-cloudera" >> ~/.bash_profile' -become
ERROR! failed at splitting arguments, either an unbalanced jinja2 block or quotes: echo export JAVA_HOME=//usr/java/jdk1.7.0_67-cloudera" >> ~/.bash_profile
[root@ans0101 ansible]# ansible -i inventory cm-r01nn01 -m shell -a 'echo export PATH=\$JAVA_HOME/bin:\$PATH >> ~/.bash_profile' -become
cm-r01nn01 | SUCCESS | rc=0 >>
[root@ans0101 ansible]# ansible -i inventory cm-r01nn01 -m shell -a 'echo export JAVA_HOME=/usr/java/jdk1.7.0_67-cloudera >> ~/.bash_profile' -become
cm-r01nn01 | SUCCESS | rc=0 >>
[root@ans0101 ansible]# ssh cm-r01nn01
Last login: Sat Jun 2 09:26:59 2018 from 192.168.0.142
[root@cm-r01nn01 ~]# vi .bash_profile
[root@cm-r01nn01 ~]#
[root@cm-r01nn01 ~]#
[root@cm-r01nn01 ~]# logout
Connection to cm-r01nn01 closed.
[root@ans0101 ansible]# ansible -i inventory cm-r01nn01 -m shell -a 'echo export JAVA_HOME=/usr/java/jdk1.7.0_67-cloudera >> ~/.bash_profile' -become
cm-r01nn01 | SUCCESS | rc=0 >>
[root@ans0101 ansible]# ansible -i inventory cm-r01nn01 -m shell -a 'echo export PATH=\$JAVA_HOME/bin:\$PATH >> ~/.bash_profile' -become
cm-r01nn01 | SUCCESS | rc=0 >>
[root@ans0101 ansible]# ansible -i inventory cm-r01nn01 -m shell -a 'java -version' -become
cm-r01nn01 | FAILED | rc=127 >>
/bin/bash: java: command not foundnon-zero return code
[root@ans0101 ansible]# ssh cm-r01nn01
Last login: Sat Jun 2 09:29:01 2018 from 192.168.0.142
[root@cm-r01nn01 ~]# java -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
[root@cm-r01nn01 ~]# cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export JAVA_HOME=/usr/java/jdk1.7.0_67-cloudera
export PATH=$JAVA_HOME/bin:$PATH
[root@cm-r01nn01 ~]# cat .bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
export PERL_LOCAL_LIB_ROOT="$PERL_LOCAL_LIB_ROOT:/root/perl5";
export PERL_MB_OPT="--install_base /root/perl5";
export PERL_MM_OPT="INSTALL_BASE=/root/perl5";
export PERL5LIB="/root/perl5/lib/perl5:$PERL5LIB";
export PATH="/root/perl5/bin:$PATH";
export JAVA_HOME=/usr/java/jdk1.7.0_67-cloudera
export PATH=/bin:/sbin:/bin:/usr/sbin:/usr/bin
export PATH=$JAVA_HOME/bin:$PATH
[root@cm-r01nn01 ~]#
[root@ans0101 ansible]# ansible -i inventory cm-r01nn01 -m shell -a 'echo $PATH' -become
cm-r01nn01 | SUCCESS | rc=0 >>
/sbin:/bin:/usr/sbin:/usr/bin
[root@ans0101 ansible]# ansible -i inventory cm-r01nn01 -m shell -a 'echo \$PATH' -become
cm-r01nn01 | SUCCESS | rc=0 >>
$PATH
[root@ans0101 ansible]# ansible -i inventory cm-r01nn01 -m shell -a 'echo $PATH' -become
cm-r01nn01 | SUCCESS | rc=0 >>
/sbin:/bin:/usr/sbin:/usr/bin
[root@ans0101 ansible]# ssh cm-r01nn01
Last login: Sat Jun 2 09:32:43 2018 from 192.168.0.142
[root@cm-r01nn01 ~]# echo $PATH
/usr/java/jdk1.7.0_67-cloudera/bin:/usr/java/jdk1.7.0_67-cloudera/bin:/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@cm-r01nn01 ~]#