# How can I change the path for specific host

**URL:** <https://forum.ansible.com/t/how-can-i-change-the-path-for-specific-host/23236>\
**Category:** Ansible Project\
**Created:** [December 12, 2016, 2:29pm UTC](https://forum.ansible.com/t/how-can-i-change-the-path-for-specific-host/23236 "2016-12-12T14:29:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guilherme\_Ueno](https://avatars.discourse-cdn.com/v4/letter/g/58f4c7/32.png) [@Guilherme\_Ueno](https://forum.ansible.com/u/Guilherme_Ueno)\
**Post date:** [December 12, 2016, 2:29pm UTC](https://forum.ansible.com/t/how-can-i-change-the-path-for-specific-host/23236/1 "2016-12-12T14:29:49Z")

</div>

Hi all,

I have to copy a file into a directory to specific hosts, but the path changes for specific hosts.

Ex.:

Inventory:

[webserver]  
hosta  
hostb

task: Copy a file into:

hosta: /usr/app/abc/dir  
hostb: /usr/app/def/dir

But, I don’t know how to use those variables in the “same task” using “webserver” as target.

thank you,  
Guilherme.

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [December 12, 2016, 4:22pm UTC](https://forum.ansible.com/t/how-can-i-change-the-path-for-specific-host/23236/2 "2016-12-12T16:22:12Z")

</div>

If they're in different groups, make the path a group var.  
If they're in the same groups, make the path a host var.

---

<div class="post-metadata">

**Author:** ![Guilherme\_Ueno](https://avatars.discourse-cdn.com/v4/letter/g/58f4c7/32.png) [@Guilherme\_Ueno](https://forum.ansible.com/u/Guilherme_Ueno)\
**Post date:** [December 12, 2016, 6:10pm UTC](https://forum.ansible.com/t/how-can-i-change-the-path-for-specific-host/23236/3 "2016-12-12T18:10:20Z")

</div>

Hi Dick,

Thank you for your attention, but what you mean when you says “host var”?

INVENTORY:  
[webserver]

hosta

hostb

TASK1:

- name: copy script to server A

copy: src=jboss.sh dest=/usr/app/abc/dir mode=u+rwx

TASK2:

- name: copy script to server B  
copy: src=jboss.sh dest=/usr/app/def/dir mode=u+rwx

COMMAND:

ansible-playbook -i inventory environment --limit webserver

The destination is different on both hosts and I can’t reduce those tasks to only one, because of subdirectories “abc” and “def”.

Thank you again,  
Guilherme.

---

<div class="post-metadata">

**Author:** ![Greg\_Langford](https://avatars.discourse-cdn.com/v4/letter/g/f1d935/32.png) [@Greg\_Langford](https://forum.ansible.com/u/Greg_Langford)\
**Post date:** [December 13, 2016, 8:31am UTC](https://forum.ansible.com/t/how-can-i-change-the-path-for-specific-host/23236/4 "2016-12-13T08:31:27Z")

</div>

You can use host vars or group vars like the following.

In the root of your ansible repo where your inventory file sits create the following yaml files for host vars

host\_vars/hosta  
host\_vars/hostb

Within these files you can now specify variables e.g within host\_vars/hosta

file\_path: /file/path/for/hosta

And then create file host\_vars/hostb

file\_path: /file/path/for/hostb

Within your playbook you can now specify

TASK1:

- name: copy script to server A

copy: src=jboss.sh dest=“{{ file\_path }}” mode=u+rwx

This will use the variable from within your host\_vars file, its the same for group vars only the folder is called group\_vars and you would instead use the group names instead of the host names.

Kind Regards

---

<div class="post-metadata">

**Author:** ![Guilherme\_Ueno](https://avatars.discourse-cdn.com/v4/letter/g/58f4c7/32.png) [@Guilherme\_Ueno](https://forum.ansible.com/u/Guilherme_Ueno)\
**Post date:** [December 13, 2016, 2:14pm UTC](https://forum.ansible.com/t/how-can-i-change-the-path-for-specific-host/23236/5 "2016-12-13T14:14:25Z")

</div>

Hi Greg, I’ve just created the vars as you said and it worked, thank you very much!

---

<div class="post-metadata">

**Author:** ![Greg\_Langford](https://avatars.discourse-cdn.com/v4/letter/g/f1d935/32.png) [@Greg\_Langford](https://forum.ansible.com/u/Greg_Langford)\
**Post date:** [December 15, 2016, 11:12am UTC](https://forum.ansible.com/t/how-can-i-change-the-path-for-specific-host/23236/6 "2016-12-15T11:12:37Z")

</div>

No problem, you are most welcome.

Kind Regards
