1
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 5 years have passed since last update.

Writing Custom Ansible Module with PyCharm quickly

Last updated at Posted at 2018-11-11

目標

The Goal

は次のイメージのように、カスタマイズしたAnsibleモジュールをPyCharmを利用して作成することです。

is to build custom ansible module with PyCharm like following:

image.png

tkim_ansibl_module ディレクトリ構成

file structure

上記のイメージで全てのことがお分かりになると思いますが、少し補足を申しますと、

위의 이미지 만으로 충분히 설명하고 있다고 생각하지만, 그래도 보충하자면,

I believe that the above pycharm image shows everything enough but to say extra explanation,

play.yml
[library]
  |_ tkim_host_check.py
  |_ test_tkim_host_check.py

pycharm projectを作る時に、Conda環境を選びました。

to make a project with pycharm, I chose Conda Environment.

image.png

Script内容

Ansible Script:


- hosts: localhost
  tasks:
    - name: tast that my module works
      tkim_host_check:
      register: result

    - debug: var=result

tkim_host_check.py


#!/usr/bin/python
from ansible.module_utils.basic import *


def main():
    module = AnsibleModule(argument_spec={})
    response = {
        "basic process check": "ok(dummy)",
        "basic process disk": "ok(dummy)",
        "basic process memory": "ok(dummy)",
        "advanced configuration check": "ok(dummy)",
    }
    module.exit_json(changed=False, meta=response)


if __name__ == '__main__':
    main()

作ろうとした目的

このモジュールは、次のような場合に使用するために実装されました。
이 스크립트는 다음과 같은 경우에 사용하기 위해서 구현되었습니다.
This script is encouraged for use in the following cases:

  1. エージェントレスホスト検査(에이전트없는 호스트 검사, Agentless Host Check)
  2. 定型化されたホスト検査(정형화된 호스트 검사, formal host checking)
  3. マルチレイヤの対応(멀티레이어의 대응, handling multi-layers)

すべての接続された端末に同時にコマンドを投げられる端末エミュレータの機能やtmuxのようなツールを利用しても可能ですが、定められている内容をすぐに対応するには、Code As A Infrastructure化するのも良いと思います。

모든 연결된 터미널에 동시에 명령을 내릴 수 있는 터미널에뮬레이터의 기능이나 tmux와 같은 툴을 이용해도 가능하지만, 정해져 있는 내용을 빨리 대응하기 에는 Code As A Infrastructure 화 하는 것도 좋습니다

It is possible to use a terminal emulator feature that can throw commands at the same time to all connected terminals ( or server-side tool like tmux), but in order to respond quickly to the formalized script, I believe that Code As A Infrastructure is a good idea also.

1
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
1
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?