kishan agarwal
kishan agarwal

Reputation: 53

Not able to run custom module

I created a custom module called pingtest which pings all the server using the ping command. I have created a shell script for that and later placed it inside the library directory of the playbook directory. When I wrote a playbook to use that module it gives me an error saying

" fatal: [ansibleclient]: FAILED! => {"msg": "module (pingtest) is missing interpreter line"}"

I tried to make changes in IP address but nothing seems to be working and I am using Ansible version 2.7.9.

The pingtest module:

#/bin/bash /bin/sh
 source $1 >/home/vagrant/ping.out>&1

 TARGET=${target:-127.0.0.1}
ping -c 1 ${TARGET} >/home/vagrant/ping.out 2>/home/vagrant/ping.err

if [ $? == 0 ];
then
echo "{\"changed\": true, \"rc\": 0}"
else
  echo "{\"failed\": true, \"msg\": \"failed to ping\", \"rc\": 1}"
fi

The playbook to use pingtest module:

---
- hosts: linux
  tasks:
  - name: Calling pingtest module
    pingtest:
      target: 192.168.111.31

I expected that module will run but don't know why I am getting below error

fatal: [ansibleclient]: FAILED! => {"msg": "module (pingtest) is missing interpreter line"}
fatal: [ubuntuclient]: FAILED! => {"msg": "module (pingtest) is missing interpreter line"}

Upvotes: 1

Views: 386

Answers (1)

Matt P
Matt P

Reputation: 2625

The first line in your pingtest module is invalid.

Change to #!/bin/bash and it should work just fine.

Upvotes: 3

Related Questions