これは、現在のシステムからdatetimeを取得するために作成したカスタムモジュールです。私はモジュールを/ usr/share/my_modulesフォルダに入れました。可能性のあるモジュールでカスタムモジュールを作成する方法
#!/usr/bin/python
import datetime
import json
date = str(datetime.datetime.now())
print(json.dumps({
"time" : date
}))
def main():
module = AnsibleModule(
argument_spec = dict(
state = dict(default='present', choices=['present', 'absent']),
name = dict(required=True),
enabled = dict(required=True, type='bool'),
something = dict(aliases=['whatever'])
)
)
module.exit_json(changed=True, something_else=12345)
module.fail_json(msg="Something fatal happened")
from ansible.module_utils.basic import *
from ansible.module_utils.basic import AnsibleModule
if __name__ == '__main__':
main()
そして、私は
timetestコマンドansibleローカル-mを使用して、それを実行しようとすると、それは私のカスタムモジュールを実行していない理由は、今、私はこのエラーに
127.0.0.1 | FAILED! => {
"failed": true,
"msg": "The module timetest was not found in configured module paths. Additionally, core modules are missing. If this is a checkout, run 'git submodule update --init --recursive' to correct this problem."
}
を取得していますか?この問題を解決するのを手伝ってください。あなたの脚本が存在するディレクトリ内library
ディレクトリを作成することができます
ありがとうArbab。私はこのパスをansible.cfgで言及するべきですか? –
モジュールをライブラリに入れた後も、エラーを解決できません。 –
これで、playbook内のライブラリフォルダに置かれたカスタム作成モジュールを実行できるようになりました。また、アドホックコマンドによっても実行できます。おかげさまでArbab。 –