0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Ansible—自作モジュール開発の第一歩 ( example モジュールの作成 )

Last updated at Posted at 2018-08-04

モジュール実行スクリプトの作成

some_key="some value" を返すだけのスクリプト。

ansible_module/example.py
#!/usr/bin/python
# -*- coding: utf-8 -*-

from ansible.module_utils.basic import AnsibleModule

module = AnsibleModule(
    argument_spec=dict()
)

result = dict(
    some_key="some value",
)

module.exit_json(**result)

別にpythonスクリプトでなくても良いが、ここではpythonを使う。

ansibleコマンドを実行

example.py が存在するディレクトリを --module-path で指定する。

$ ansible localhost -m 'example' --module-path=./ansible_module

localhost | SUCCESS => {
    "changed": false,
    "some_key": "some value"
}

実行できた!

ダウンロード用

example.py を git clone する場合はこちら

git clone https://gist.github.com/YumaInaura/829b06cbf1c2ad5fa0a823ba24f8afbf/ ansible_module

環境

  • ansible 2.6.1 ( installed by homebrew )
  • Mac OSX High Sierra 10.13.4

参考

Gist

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?