Ansible. part 1.

Example of using Ansible for checking online calls from many of servers from command line:

Ansible check online calls from few servers through ssh:
docs: https://docs.ansible.com/ansible/latest/installation_guide/intro_configuration.html

Control node :


apt update -y
apt install ansible -y

Create /etc/ansible/hosts file

all:
   hosts:
     123.123.123.123:
     123.123.123.124:
     123.123.123.125:
     123.123.123.126:

Check connecting to hosts:

ansible all -m ping

You may see error like this:
“msg”: “Failed to connect to the host via ssh:
WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!\r\n
Someone could be eavesdropping on you right now (man-in-the-middle attack)!\r\n
It is also possible that a host key has just been changed.\r\n
The fingerprint for the ECDSA key sent by the remote host is\nSHA256:sdfsdfsdfsdfsdfsdfsdfsdf.\r\n
Please contact your system administrator.\r\n
Add correct host key in /root/.ssh/known_hosts to get rid of this message.\r\n
Offending ECDSA key in /root/.ssh/known_hosts:6\r\n remove with:\r\n
ssh-keygen -f \”/root/.ssh/known_hosts\” -R \”123.123.123.123\”\r\n
ECDSA host key for 123.123.123.123 has changed and you have requested strict checking.\r\n
Host key verification failed.”,
“unreachable”: true

to fix it you may to run on control node:

ssh-keygen -f "/root/.ssh/known_hosts" -R "123.123.123.123"

To check count of calls from from hosts

ansible all -a "asterisk -rx \"core show calls\""

if everything works fine, you will see:

123.123.123.123| CHANGED | rc=0 >>
328 active calls
691163 calls processed
123.123.123.124 | CHANGED | rc=0 >>
167 active calls
346948 calls processed
123.123.123.125 | CHANGED | rc=0 >>
382 active calls
371352 calls processed
123.123.123.126 | CHANGED | rc=0 >>
356 active calls
691689 calls processed

if you want to use complex command you may use this:

ansible all -m shell -a "asterisk -rx \"core show calls\" | grep 'active' && asterisk -rx \"fax show sessions\" | grep 'FAX session' "
123.123.123.123 | CHANGED | rc=0 >>
388 active calls
117 FAX sessions
123.123.123.124 | CHANGED | rc=0 >>
188 active calls
59 FAX sessions
123.123.123.125 | CHANGED | rc=0 >>
393 active calls
123 FAX sessions
123.123.123.126 | CHANGED | rc=0 >>
381 active calls
119 FAX sessions

Tags: , ,
| 25/11/2021 | Posted in ansible |

Leave a Reply