Changing the target server name

26 views
Skip to first unread message

Praveen Kumar Singh

unread,
Feb 24, 2021, 10:17:32 AM2/24/21
to ansible...@googlegroups.com
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

Stefan Hornburg (Racke)

unread,
Feb 25, 2021, 2:23:24 AM2/25/21
to ansible...@googlegroups.com
Hello Praveen,

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

Regards
Racke

> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAJK1W%3Dzg-tBoPhG6dAY889xGPrhfScVu1Q_D_jApPyV64bcJLw%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAJK1W%3Dzg-tBoPhG6dAY889xGPrhfScVu1Q_D_jApPyV64bcJLw%40mail.gmail.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

OpenPGP_signature

Praveen Kumar Singh

unread,
Feb 25, 2021, 2:32:30 AM2/25/21
to ansible...@googlegroups.com, ra...@linuxia.de
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.

---
  - hosts: SQLSERVER
    vars:
      DbName_Source:
      ansible_become_user: Ansible
      ansible_become_pass: xyz@123
      DbName_Destination:

    vars_prompt:
     - name: DbName_Source
       private: no
       prompt: Source Database
       default:

     - name: DbName_Destination
       private: no
       prompt: destination Database
       default:


    tasks:
     - name: DB Backup
       win_shell: |
          $Backup = "BACKUP DATABASE {{ DbName_Source }} TO DISK = 'E:\Backup\{{ DbName_Source }}-Databasebackup.bak'"
          Invoke-SqlCmd -Query $Backup

     - name: Sync SQLSERVER to SQLSERVER2
       become: yes
       become_method: runas
       become_flags: logon_type=new_credentials logon_flags=netcredentials_only
       win_copy:
           src: E:\BACKUP\
           dest: \\xx.xxx.xxx.xx\E$\BACKUP\
           remote_src: yes

     - name: DB Restore
       win_shell: |
          $Restore = "RESTORE DATABASE {{ DbName_Destination }} FROM
                      DISK = N'E:\BACKUP\{{ DbName_Source }}-Databasebackup.bak'
                      WITH  FILE = 1,
                      MOVE N'{{ DbName_Source }}' TO N'D:\SQLDATA\MSSQL15.MSSQLSERVER\MSSQL\DATA\{{ DbName_Destination }}.mdf',
                      MOVE N'{{ DbName_Source }}_log' TO N'L:\SQLLOG\{{ DbName_Destination }}_log.ldf',
                      NOUNLOAD,  REPLACE,  STATS = 5"
          Invoke-SqlCmd -Query $Restore

Thanks and Regards,
Praveen Singh
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/88f6f91c-c7a5-23a1-73d2-a39dc8614396%40linuxia.de.

Stefan Hornburg (Racke)

unread,
Feb 25, 2021, 2:40:51 AM2/25/21
to ansible...@googlegroups.com
On 2/25/21 8:32 AM, 'Praveen Kumar Singh' via Ansible Project wrote:
> 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
Racke
> On Wed, Feb 24, 2021 at 11:23 PM Stefan Hornburg (Racke) <ra...@linuxia.de <mailto:ra...@linuxia.de>> wrote:
>
> On 2/24/21 4:17 PM, 'Praveen Kumar Singh' via Ansible Project wrote:
> > 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
>         Racke
>
> > --
> > You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to
> > ansible-proje...@googlegroups.com <mailto:ansible-project%2Bunsu...@googlegroups.com>
> <mailto:ansible-proje...@googlegroups.com <mailto:ansible-project%2Bunsu...@googlegroups.com>>.
> <https://groups.google.com/d/msgid/ansible-project/CAJK1W%3Dzg-tBoPhG6dAY889xGPrhfScVu1Q_D_jApPyV64bcJLw%40mail.gmail.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/CAJK1W%3Dzg-tBoPhG6dAY889xGPrhfScVu1Q_D_jApPyV64bcJLw%40mail.gmail.com?utm_medium=email&utm_source=footer>>.
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-project%2Bunsu...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/88f6f91c-c7a5-23a1-73d2-a39dc8614396%40linuxia.de
> <https://groups.google.com/d/msgid/ansible-project/88f6f91c-c7a5-23a1-73d2-a39dc8614396%40linuxia.de>.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAJK1W%3Dw_eRASn-Z-NhbBPHao-Sb4ytoKRz3uG9se%3DAAiVb_%3D9g%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAJK1W%3Dw_eRASn-Z-NhbBPHao-Sb4ytoKRz3uG9se%3DAAiVb_%3D9g%40mail.gmail.com?utm_medium=email&utm_source=footer>.
OpenPGP_signature

Praveen Kumar Singh

unread,
Feb 25, 2021, 4:03:49 AM2/25/21
to ansible...@googlegroups.com, ra...@linuxia.de
Thank you so much Stefan. That worked.

Thanks and regards
Praveen Singh


To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4eb20aa8-ccd2-6ca4-8f18-7ebe6514ea31%40linuxia.de.
Reply all
Reply to author
Forward
0 new messages