# Always append a '/' to variable whose value is supplied as extra vars

**URL:** <https://forum.ansible.com/t/always-append-a-to-variable-whose-value-is-supplied-as-extra-vars/22411>\
**Category:** Ansible Project\
**Created:** [August 29, 2016, 11:43am UTC](https://forum.ansible.com/t/always-append-a-to-variable-whose-value-is-supplied-as-extra-vars/22411 "2016-08-29T11:43:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [August 29, 2016, 11:43am UTC](https://forum.ansible.com/t/always-append-a-to-variable-whose-value-is-supplied-as-extra-vars/22411/1 "2016-08-29T11:43:31Z")

</div>

I have a variable config\_src which i use in a lot many places (host vars, inventory file, playbook) and its value is supplied at the run time as extra vars (-e)  
This variable is actually a path variable, so i need to ensure that it is always ending in a ‘/’. As this variable is in use in a lot of places, i want to make sure that a ‘/’ is appended to it in a single place as applying some filter to all the places is not feasible. My inventory file is something that is common for all playbooks, so i think i should append the ‘/’ somewhere in the inventory file only.  
How can i do that ?

---

<div class="post-metadata">

**Author:** ![ayush.kumar](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@ayush.kumar](https://forum.ansible.com/u/ayush.kumar)\
**Post date:** [August 31, 2016, 12:34am UTC](https://forum.ansible.com/t/always-append-a-to-variable-whose-value-is-supplied-as-extra-vars/22411/2 "2016-08-31T00:34:10Z")

</div>

One thing I could think of is instead of passing in config\_src as the -e arg, pass in dummy\_src and declare config\_src = {{ dummy\_src|some\_filter }} as a variable somewhere that makes sense for your specific structure (probably a top level default variable based on your initial post).

It might not even be necessary. For file paths, multiple slashes are collapsed into one on most OSes I’ve tried.

---

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [August 31, 2016, 6:28am UTC](https://forum.ansible.com/t/always-append-a-to-variable-whose-value-is-supplied-as-extra-vars/22411/3 "2016-08-31T06:28:43Z")

</div>

Thanks for the Idea ayush 🙂

Custom filter seemed to much work as there are a lot of possibilities to cover. What i ended up doing is appending a ‘/’ wherever the var is used, like - {{config\_src}}/  
This ensure that you have to give correct path to point inside the folder. Any extra ‘/’ will be ignored of course.
