Search code examples
linuxnetwork-programmingsalt-project

How to get ip address of minion through which it is connected to master


I want to retrieve IP address of minion through which it is communicating with master.

salt '*' network.ip_addrs
salt '*' cmd.run "curl ifconfig.me"
salt '*' cmd.run "curl -s icanhazip.com"

Using above commands minion returns ip addresses of all interfaces.

How to filter ip address to get the ip address through which it is connected to master


Solution

  • The easiest way is:

    salt-run manage.present show_ip=true
    

    If you know the subnet that the master and minion share:

    salt '*' network.ip_addrs cidr=10.2.16.0/24
    

    Otherwise, you can check the socket table:

    salt '*' cmd.run "ss -nt | grep :4505 | awk '{print \$4}'"