Change bash_profile dynamically.

653 views
Skip to first unread message

Darup tek

unread,
Aug 29, 2014, 9:25:00 PM8/29/14
to ansible...@googlegroups.com
I am little clueless on how to solve this issue.

There are couple of hosts I need to remotely change the .bash_profile.

Locally I run the command this way.

echo ""# .bash_profile

 # Get the aliases and functions

if [ -f ~/.bashrc ]; then

        . ~/.bashrc

fi

 

# User specific environment and startup programs

export JAVA_HOME=/xxx/xxx/xxx/jdk1.7.0_21

PATH=\$PATH:\$HOME/bin:\$JAVA_HOME/bin

export HOST_NAME=`hostname -s` " > .bash_profile


How do I solve this problem from playbook. I need the task to copy the .bash_profile reflecting the hostname of the server.

It has to execute the `hostname -s` .


I can template and copy, but cannot I need it to do the command substitution.


Thanks,

Darup.

 





Darup tek

unread,
Aug 29, 2014, 9:39:00 PM8/29/14
to ansible...@googlegroups.com
currently,I am solving this problem making it as a script and using

  - script: script_change_bash_profile.sh

Is there a better way than this. 

mvermaes

unread,
Aug 30, 2014, 1:56:17 AM8/30/14
to ansible...@googlegroups.com
Hi Darup, I think you were on the right track with the template approach, but instead of using the shell command, you can use the built-in Ansible fact 'ansible_hostname'. So the bottom line of your template file would be:

export HOST_NAME={{ ansible_hostname }}

You can read more about facts at http://docs.ansible.com/playbooks_variables.html#information-discovered-from-systems-facts.

Hope that helps.

Michael

Darup tek

unread,
Aug 30, 2014, 2:43:46 AM8/30/14
to ansible...@googlegroups.com
Thank You
Reply all
Reply to author
Forward
0 new messages