# Use shell/command to update text file with variable name

**URL:** <https://forum.ansible.com/t/use-shell-command-to-update-text-file-with-variable-name/28410>\
**Category:** Ansible Project\
**Created:** [August 23, 2018, 7:37pm UTC](https://forum.ansible.com/t/use-shell-command-to-update-text-file-with-variable-name/28410 "2018-08-23T19:37:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MPb](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@MPb](https://forum.ansible.com/u/MPb)\
**Post date:** [August 23, 2018, 7:37pm UTC](https://forum.ansible.com/t/use-shell-command-to-update-text-file-with-variable-name/28410/1 "2018-08-23T19:37:34Z")

</div>

I have a process that is exporting xml config from an application and the exported xml config contains the server name of the server it was exported from.

A grep contains would contain a list of these:

./config\_1.xml: ns:serverNamemyservername.dom.com\</ns:serverName\>  
./config\_2.xml: ns:serverNamemyservername.dom.com\</ns:serverName\>

I want to make them via an ansible task:

./config\_1.xml: ns:serverName{{ gold\_server\_conf }}\</ns:serverName\>  
./config\_2.xml: ns:serverName{{ gold\_server\_conf }}\</ns:serverName\>

Something like this?? is wrong because Ansible will just think {{ gold\_server\_conf }} is a variable… but i want it to treat it just as text

- name: template out the server name  
shell:  
sed -i ‘s/{{ ansible\_hostname }}/{{ gold\_server\_conf }}/g’ \*

---

<div class="post-metadata">

**Author:** ![mhalano](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mhalano/32/1815_2.png) [@mhalano](https://forum.ansible.com/u/mhalano)\
**Post date:** [August 23, 2018, 7:54pm UTC](https://forum.ansible.com/t/use-shell-command-to-update-text-file-with-variable-name/28410/2 "2018-08-23T19:54:37Z")

</div>

You could use a template.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 23, 2018, 8:34pm UTC](https://forum.ansible.com/t/use-shell-command-to-update-text-file-with-variable-name/28410/3 "2018-08-23T20:34:09Z")

</div>

When in doubt try escaping 🙂

&nbsp;&nbsp;- name: template out the server name  
&nbsp;&nbsp;&nbsp;&nbsp;shell:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sed -i 's/{{ ansible\_hostname }}/\{\{ gold\_server\_conf \}\}/g' \*

---

<div class="post-metadata">

**Author:** ![Badraj\_Angirekula](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@Badraj\_Angirekula](https://forum.ansible.com/u/Badraj_Angirekula)\
**Post date:** [August 27, 2018, 9:29am UTC](https://forum.ansible.com/t/use-shell-command-to-update-text-file-with-variable-name/28410/4 "2018-08-27T09:29:40Z")

</div>

Hi all,

please help me.

Build ec2 instances with attaching multiple tags names :-  
For example- I have launched one ec2 instance with tag name “websever1” the next builds of ec2 instances should start with tag name webserver2 , webserver3 … automatically.

Note: No two ec2 instances have same tag name.
