DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Automating Unix Security Across Hybrid Clouds
  • Cloud Automation Excellence: Terraform, Ansible, and Nomad for Enterprise Architecture
  • Streamlining Event Data in Event-Driven Ansible
  • Clean Up Event Data in Ansible Event-Driven Automation

Trending

  • LangChainGo vs Genkit Go: Where Genkit Shines
  • One Database, Two Models: Building AI-Friendly Java Applications With MySQL JSON Duality Views
  • ScyllaDB in Enterprise Java: High-Performance NoSQL With Eclipse JNoSQL
  • Taming Parameter Sniffing in SQL Server 2022 With PSP Optimization

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Ansible Galaxy: Ping Windows Servers

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.

By 
Manoj Kumar
·
Apr. 08, 17 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
8.5K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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!

Ansible (software) Galaxy (computational biology)

Opinions expressed by DZone contributors are their own.

Related

  • Automating Unix Security Across Hybrid Clouds
  • Cloud Automation Excellence: Terraform, Ansible, and Nomad for Enterprise Architecture
  • Streamlining Event Data in Event-Driven Ansible
  • Clean Up Event Data in Ansible Event-Driven Automation

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook