Change bash_profile dynamically.

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.

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.

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

Thank You