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

45 views
Skip to first unread message

Larry Fast

unread,
Nov 17, 2015, 2:23:43 PM11/17/15
to Ansible Project
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()

Toshio Kuratomi

unread,
Nov 17, 2015, 3:22:42 PM11/17/15
to ansible...@googlegroups.com
You could try explicitly setting the ANSIBLE_LIBRARY environment
variable.to the path to you library directory

-Toshio

Larry Fast

unread,
Nov 17, 2015, 6:42:10 PM11/17/15
to Ansible Project
Turns out it requires the #! at the start. Don't know if the 2nd line is required.

#!/usr/bin/python

# -*- coding: utf-8 -*-

Toshio Kuratomi

unread,
Nov 17, 2015, 11:23:25 PM11/17/15
to ansible...@googlegroups.com

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

Reply all
Reply to author
Forward
0 new messages