how does Ansible find my first hand made module? I put it in ./library

I created my first module using your python boilerplates. How do I get my Ansible Playbook to find it? According to the docs, I placed it in ./library/env_checks.py but I still get “ERROR: enviro_checks_ansmodule is not a legal parameter in an Ansible task or handler” What steps am I missing?

Playbook code

  • hosts: myhosts
    tasks:
  • env_checks:

Module Code:

def main():
module = AnsibleModule(
argument_spec = dict(
state = dict(default=‘present’, choices=[‘present’, ‘absent’])
)
)
module.exit_json(changed=True, otherthing=False)

from ansible.module_utils.basic import *
if name == ‘main’:
main()

You could try explicitly setting the ANSIBLE_LIBRARY environment
variable.to the path to you library directory

-Toshio

Turns out it requires the #! at the start. Don’t know if the 2nd line is required.

#!/usr/bin/python

-- coding: utf-8 --

Ah, yeah that’s needed so that ansible can tell this is a module written in python vs ruby or perl or another language. The second line is nice boilerplate but not strictly needed. It tells python what encoding to use when it reads the file. It’s usually only needed when you embed a non-ascii literal in the file. (For instance, someone puts their name in a comment and their name has accents)

-Toshio