Skip to content

Instantly share code, notes, and snippets.

@oxagast
Last active November 16, 2024 02:34
Show Gist options
  • Save oxagast/3ac9e5681039e2917e22163a5a60f2c2 to your computer and use it in GitHub Desktop.
Save oxagast/3ac9e5681039e2917e22163a5a60f2c2 to your computer and use it in GitHub Desktop.
Ansible online connectivity check
# Creator: oxagast
#
# usage:
# ansible-playbook -i inventory.yml conn_chk.yml --extra-vars "hostname=google.com"
# or..
# ansible-playbook -i inventory.yml conn_chk.yml
---
- hosts: linux
gather_facts: False
connection: local
vars:
ip: "{{ hostname | default('8.8.8.8', true) }}"
tasks:
- name: Pinging host {{ ip }}
shell: ping -w 3 -c 1 {{ ip }}
ignore_errors: false
- hosts: freebsd
gather_facts: False
connection: local
vars:
ip: "{{ hostname | default('8.8.8.8', true) }}"
tasks:
- name: Pinging host {{ ip }}
shell: ping -t 3 -c 1 {{ ip }}
ignore_errors: false
- hosts: windows
gather_facts: False
connection: local
vars:
ip: "{{ hostname | default('8.8.8.8', true) }}"
tasks:
- name: Pinging host {{ ip }}
win_command: ping -w 3 -n 1 {{ ip }}
ignore_errors: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment