{{announcement.body}}
{{announcement.title}}

Ansible Galaxy: Ping Windows Servers

DZone 's Guide to

Ansible Galaxy: Ping Windows Servers

In this quick tutorial, we learn how to ping a Windows server, in order to check if the host is reachable and we are indeed connected.

· Web Dev Zone ·
Free Resource

This article shows how you can ping Windows Servers (2008 and 2012) using Ansible Galaxy. You may hook up any plays or windows modules which I will demonstrate in future articles.

Prerequisites:

- Ansible installed Linux Controller (I am using Ubuntu 16).

- Windows Server 2008 (180-day trial virtual machine using  VMWare Player).

- Windows Server 2012 (180-day trial virtual machine using  VMWare Player).

Step 1. In our Ansible controller create a directory named "winservers."

Image title

Step 2. Open the Terminal window and browse to the newly created folder "winservers."

Step 3. Create an inventory file (hosts) under  /winservers/ with server the following information:

[winservers]
192.168.152.132
192.168.152.133

[winservers:vars]
ansible_ssh_user=administrator
ansible_ssh_pass=P@ssword1234
ansible_ssh_port=5985
ansible_connection=winrm

Here:

[winservers] is our group of Windows Servers.

[winservers-vars] contains the ssh access information for both the servers. Both the servers have been configured to have a user named 'Administrator' and the same password.

We are using winrm to connect to the servers.

Step 4. The Configuration file.

Since we are not using the default hosts file (/etc/ansible/hosts), we need to instruct Ansible to use the new hosts file that we created in step3.

Create a new file named ansible.cfg and use the following as it's content:

[defaults]
inventory = /home/mbalotia/AnsiblePrac/winservers/hosts

Step 5. We will create a galaxy named "ping."

Command: ansible-galaxy init ping  

 mbalotia@mbalotia-controller:~/AnsiblePrac/winservers$ ansible-galaxy init ping

- ping was created successfully

This command creates our galaxy under  /winservers/ping with the following structure:

Image title

Please note ping is our new role, we will now create a task to ping our Windows Servers.

Step 6. Edit /ping/tasks/main.yml and replace its content with the following:

---
# This uses the win_ping module to test connectivity to Windows hosts
- name: Ping All windows servers 
   win_ping:

We are going to use the win_ping module for this.

Step 7. Create a playbook named pingservers.yml under /winservers/ with the following content:

---
- hosts: all
   roles:
   - { role: "ping" }

Quick explanation of the above code:

Hosts: all (targets all the servers in our inventory).

Roles: lists all the roles that we want to execute, in our case there is only one role named "ping."

Our final directory structure for /winservers looks like:

Image title


Step 8. Finally, run the playbook by typing:

 ansible-playbook pingservers.yml 
Image title

Congratulations! You are now able to ping your windows servers using Ansible Galaxy!

Topics:
ansible ,ansible galaxy ,web dev ,windows server

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}