Run a unix script on ansible server that connect to remote servers.

Hi, all

I have an existing unix shell script that does ssh to connect to remote servers to search FAILED key word through logs on the remote server. If the logs contain FAILED key word, sftp to the servers to bring the logs to a central server and analyzes them.
Now we want to launch the unix script from Ansible or in the future from Ansible Tower.

Ansible shell, script and command modules are to copy or run UNIX script on remote servers not on Ansible server. In my case, I don’t want to copy the script to run on remote servers. I want to run the script on Ansible server. Is there a way to accomplish this in Ansible? Thanks.

command module does that.
The "hosts:" keyword in a play says which hosts the play is run on, localhost aka Ansible controller is a valid host.

Alternative you have
  delegate_to: localhost

Thanks for the reply, Kai

After I changed the host to local host name in hosts field of yml file. I ran it without error but I don’t see it get logs from remote servers to local /tmp directory. If I ran UNIX script, it takes logs to local /tmp/ directory from remote server.

Here is my yml file content:

That is most likely because your script assume some environment variables is set that is not set when using ssh with non-interactive shell.

Since you are using ansidev instead of localhost Ansible most likely is login in to the server with ssh(depending on you inventory).
If using ssh then you are running it under an non-interactive shell that has very few environment variables set.

Thanks, Kai

Once I changed to localhost instead host name. Ansible is able to grab logs from remote hosts.