# Change bash\_profile dynamically.

**URL:** <https://forum.ansible.com/t/change-bash-profile-dynamically/16080>\
**Category:** Ansible Project\
**Created:** [August 30, 2014, 1:25am UTC](https://forum.ansible.com/t/change-bash-profile-dynamically/16080 "2014-08-30T01:25:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darup\_tek](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@Darup\_tek](https://forum.ansible.com/u/Darup_tek)\
**Post date:** [August 30, 2014, 1:25am UTC](https://forum.ansible.com/t/change-bash-profile-dynamically/16080/1 "2014-08-30T01:25:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Darup\_tek](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@Darup\_tek](https://forum.ansible.com/u/Darup_tek)\
**Post date:** [August 30, 2014, 1:39am UTC](https://forum.ansible.com/t/change-bash-profile-dynamically/16080/2 "2014-08-30T01:39:00Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![Michael\_Vermaes](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@Michael\_Vermaes](https://forum.ansible.com/u/Michael_Vermaes)\
**Post date:** [August 30, 2014, 5:56am UTC](https://forum.ansible.com/t/change-bash-profile-dynamically/16080/3 "2014-08-30T05:56:17Z")

</div>

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](http://docs.ansible.com/playbooks_variables.html#information-discovered-from-systems-facts).

Hope that helps.

Michael

---

<div class="post-metadata">

**Author:** ![Darup\_tek](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@Darup\_tek](https://forum.ansible.com/u/Darup_tek)\
**Post date:** [August 30, 2014, 6:43am UTC](https://forum.ansible.com/t/change-bash-profile-dynamically/16080/4 "2014-08-30T06:43:46Z")

</div>

Thank You
