# Changing the target server name

**URL:** <https://forum.ansible.com/t/changing-the-target-server-name/34677>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [February 24, 2021, 3:17pm UTC](https://forum.ansible.com/t/changing-the-target-server-name/34677 "2021-02-24T15:17:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Praveen\_Kumar\_Singh](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@Praveen\_Kumar\_Singh](https://forum.ansible.com/u/Praveen_Kumar_Singh)\
**Post date:** [February 24, 2021, 3:17pm UTC](https://forum.ansible.com/t/changing-the-target-server-name/34677/1 "2021-02-24T15:17:03Z")

</div>

Is there any way to change the target server name in the middle of the playbook? This is for windows.

Thanks and Regards,  
Praveen Singh

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [February 25, 2021, 7:23am UTC](https://forum.ansible.com/t/changing-the-target-server-name/34677/2 "2021-02-25T07:23:02Z")

</div>

> Is there any way to change the target server name in the middle of the playbook? This is for windows.
> 
> Thanks and Regards,  
> Praveen Singh

Hello Praveen,

do you mind to explain which use case you have in mind?

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Praveen\_Kumar\_Singh](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@Praveen\_Kumar\_Singh](https://forum.ansible.com/u/Praveen_Kumar_Singh)\
**Post date:** [February 25, 2021, 7:32am UTC](https://forum.ansible.com/t/changing-the-target-server-name/34677/3 "2021-02-25T07:32:04Z")

</div>

Hello Stefan,

I am trying to create a playbook to perform the three below mentioned tasks which is to accomplish the database refresh. First two tasks (Database backup and Backup copy to destination server) are running fine but for the third one which is to restore the Database I need to change the host server as windows server 2. So I am not sure how I can achieve it. The playbook I am using is below:

1. Taking backup on remote windows server 1.
2. Copying that backup to another remote windows server 2.
3. Restoring that backup to remote windows server 2.

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [February 25, 2021, 7:40am UTC](https://forum.ansible.com/t/changing-the-target-server-name/34677/4 "2021-02-25T07:40:27Z")

</div>

> Hello Stefan,
> 
> I am trying to create a playbook to perform the three below mentioned tasks which is to accomplish the database refresh.  
> First two tasks (Database backup and Backup copy to destination server) are running fine but for the third one which is  
> to restore the Database I need to change the host server as windows server 2. So I am not sure how I can achieve it. The  
> playbook I am using is below:
> 
> 1) Taking backup on remote windows server 1.  
> 2) Copying that backup to another remote windows server 2.  
> 3) Restoring that backup to remote windows server 2.

Hello Praveen,

I would put both servers into "hosts" and add a condition to each task:

Either

when: inventory\_hostname == 'SQLSERVER'

or:

when: inventory\_hostname == 'SERVER2'

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Praveen\_Kumar\_Singh](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@Praveen\_Kumar\_Singh](https://forum.ansible.com/u/Praveen_Kumar_Singh)\
**Post date:** [February 25, 2021, 9:03am UTC](https://forum.ansible.com/t/changing-the-target-server-name/34677/5 "2021-02-25T09:03:23Z")

</div>

Thank you so much Stefan. That worked.

Thanks and regards  
Praveen Singh
