Skip to content

Instantly share code, notes, and snippets.

@gravcat
Created January 29, 2018 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gravcat/09a2ba7bc8250a2ea98f937bcb528f4a to your computer and use it in GitHub Desktop.
Save gravcat/09a2ba7bc8250a2ea98f937bcb528f4a to your computer and use it in GitHub Desktop.
Use the built-in win_ping module in Ansible to confirm proper connectivity and credential success for manipulating Windows hosts
---
- hosts: windows
tasks:
- name: ping
win_ping:
@adsnjhfyeqw231eas
Copy link

adsnjhfyeqw231eas commented Feb 17, 2020

@Gravecat In which file you are passing these?
ansible_user: username
ansible_password: super_secret_password
ansible_port: 5986
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore

Is this needed to add in the ping_windows_hosts.yml you are using or elsewhere? Please take a look

@gravcat
Copy link
Author

gravcat commented Feb 17, 2020

Hey @TridevGuha! Welcome to Ansible, it's a wonderful tool.

https://docs.ansible.com/ansible/latest/user_guide/intro_getting_started.html#action-create-a-basic-inventory
https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html#basics

As for the basics to get this rolling in a clean way you'll need

  • a host inventory (hosts)
  • a group_vars file (group_vars/windows.yml)
  • a playbook (main.yml)

It looks like you are putting your playbook as group_vars by mistake, and ansible is trying to read it and failing. Move windows1.yml to ../main.yml

In group_vars/windows.yml, place:

ansible_user: username
ansible_password: super_secret_password
ansible_port: 5986
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore

At this point, it should work :)


unrelated, here's an example of a simple playbook. Doesn't include group_vars like this one would, but shows how your main.yml playbook entrypoint should be!

https://gitlab.com/adrift/ansible/-/tree/master/update-rust

@adsnjhfyeqw231eas
Copy link

adsnjhfyeqw231eas commented Feb 18, 2020

@gravcat I have made the changes and It is working now! Thanks for the response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment