Zum Inhalt

Ping role

Simple Ansible ping role to verify connectivity and basic functionality of remote hosts.

Usage

Include the role in your playbook:

1
2
3
4
# playbooks/proxmox/ping.yml
- hosts: all
  roles:
    - role: ping

The role provides this tag: - ping - Execute ping test

Docs

Test connectivity to all hosts:

1
ansible-playbook -i inventory/hosts.yml playbooks/proxmox/ping.yml

Test specific host group:

1
ansible-playbook -i inventory/hosts.yml playbooks/proxmox/ping.yml --limit docker_base

What It Does

The role executes Ansible's built-in ping module, which: 1. Connects to the remote host via SSH 2. Verifies Python interpreter availability 3. Returns pong on success

Output

Successful ping:

1
2
3
TASK [ping : Ping remote host] *************************************************
ok: [docker01]
ok: [docker_base]

Failed ping:

1
2
TASK [ping : Ping remote host] *************************************************
fatal: [docker01]: UNREACHABLE! => {"msg": "Failed to connect to the host..."}

Use Cases

Use this role to: - Verify Connectivity: Test SSH access to hosts before deployment - Check Inventory: Validate inventory configuration is correct - Python Check: Ensure Python is installed on target hosts - Pre-flight Tests: Quick sanity check before running complex playbooks - Troubleshooting: Diagnose connection issues

Requirements

Remote hosts must have: - SSH access configured - Python installed (2.7+ or 3.5+) - User with sudo privileges (if needed for other tasks)

Integration

Often used at the start of playbooks:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
- name: Verify connectivity
  hosts: all
  roles:
    - role: ping

- name: Deploy services
  hosts: docker_services
  roles:
    - role: nextcloud
    - role: gitea

Dedicated Playbook

A dedicated ping playbook exists at playbooks/proxmox/ping.yml for quick connectivity tests across all infrastructure.

Not a Network Ping

Note: This is not an ICMP ping. It uses Ansible's Python-based connectivity test via SSH. For actual ICMP ping, use shell commands:

1
2
3
- name: ICMP Ping
  ansible.builtin.command: ping -c 3 {{ inventory_hostname }}
  delegate_to: localhost