Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Last active August 4, 2018 07:14
Show Gist options
  • Save YumaInaura/829b06cbf1c2ad5fa0a823ba24f8afbf to your computer and use it in GitHub Desktop.
Save YumaInaura/829b06cbf1c2ad5fa0a823ba24f8afbf to your computer and use it in GitHub Desktop.
How to start developing ansible module? ( The first step : create example module )

How to start developing ansible module? ( The first step : create example module )

Put example script

Put example.py to your local directory. ( e.g ./ansible_module/example.py )

Or you can git clone from this gist and get example.py.

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

In this case we use python script but actually modules can be written by any language.

Execute ansible command with specified module path

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

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

It works!

Versions

  • ansible 2.6.1 ( installed by homebrew )

cf.

Links

#!/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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment