【问题标题】:Not able to run custom module无法运行自定义模块
【发布时间】:2019-07-24 07:36:29
【问题描述】:

我创建了一个自定义模块 pingtest,它使用 ping 命令 ping 所有服务器。我为此创建了一个 shell 脚本,后来将其放置在 playbook 目录的 library 目录中。当我写一本剧本来使用该模块时,它给了我一个错误提示

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

我尝试更改 IP 地址,但似乎没有任何效果,我使用的是 ansible 版本 2.7.9

ping 测试模块

#/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

使用 pingtest 模块的剧本

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

我预计该模块会运行,但不知道为什么会出现错误

致命:[ansibleclient]:失败! => {"msg": "模块 (pingtest) 缺少解释器行"} 致命:[ubuntuclient]:失败! => {"msg": "模块 (pingtest) 缺少解释器行"}

【问题讨论】:

    标签: ansible vagrant


    【解决方案1】:

    您的 pingtest 模块中的第一行无效。

    更改为#!/bin/bash,它应该可以正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-02
      • 2020-12-30
      • 1970-01-01
      • 2013-10-18
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多