0

I have three hosts set up in a virtual environment in order to test things out before deployment. I was wondering if there's a way to specify that when I use:

''' ansible all -m ping '''

To ping windows hosts with win_ping and linux hosts with ping. Currently when I run the above I receive one success on the linux host and two errors for exceptions on the windows hosts. But when I run:

''' ansible all -m win_ping ''' It does the inverse where the two windows hosts will reply back and the linux box will reply with an error. The windows hosts are configured to use winrm and the linux host is using ssh. Any insight or do I need to split things between windows and linux to have things operational?

2
  • 1
    Welcome to SuperUser. Are you just looking to test reachability? If so, the net_ping command can ping both Windows and Linux destinations.
    – Doug Deden
    Commented Aug 27, 2019 at 20:22
  • it fails with an error message: ansible_network_os must be specified on this host to use platform agnostic modules. I took a look at the options for ansible_network_os and it seems like that variable is only for various switches and not system operating systems or NICs Commented Aug 28, 2019 at 14:17

1 Answer 1

2

You can't do that with an ansible command. As you've noticed the modules ping, win_ping and net_ping all have different requirements.

It's easy to do in in an ansible playbook though with the following tasks.

- hosts: all
  tasks:
  - win_ping:
    when: ansible_os_family == "Windows"
  - ping:
    when: ansible_os_family != "Windows"

You should also be able to use the raw command for a poor-mans ping but this has the downside of not testing the Python on *nix hosts:

ansible -m raw -a 'echo yay!'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .