Tracking Ansible Logins

I want to track everytime ansible logs in the remote system.

Actually, I made a simple script,


now=$(date +"%T")
echo "$USER logged in at: $now" >> /home/alphauser/ssh-entries.log

And wrote this at the end of ~/.bash_profile file,

 bash ~/

Now, every time I log in via SSH, I get the new entry in my file.

But whenever I run ansible playbook, and check this file after that, I get no record of the login which ansible made. I login via the same user.

Why is that happening?

What should I do to track the ansible logins ?

Hi Luvpreet_Singh,

Iā€™m not a 100% sure, but possibly this is due to the shell that Ansible uses while executing the code on the remote host.

I did a little digging on this, and you may be able to solve the problem via the ansible configuration file.

I was reading about the options here.

Or via Inventory variable, e.g. ansible_shell_executable - There was a bug report about this variable here.

I hope the site references can provide the help you need.


1 Like