Hi guys, I’m trying to write some modules for Ansible, but getting stumped on this error below…
OS: Arch Linux
Linux laps 4.4.37-1-lts #1 SMP Thu Dec 8 22:29:57 CET 2016 x86_64 GNU/Linux
I git cloned the ansible repo and ran the env-setup successfully:
$ source ansible/hacking/env-setup
running egg_info
creating lib/ansible.egg-info
writing top-level names to lib/ansible.egg-info/top_level.txt
writing requirements to lib/ansible.egg-info/requires.txt
writing lib/ansible.egg-info/PKG-INFO
writing dependency_links to lib/ansible.egg-info/dependency_links.txt
writing manifest file ‘lib/ansible.egg-info/SOURCES.txt’
reading manifest file ‘lib/ansible.egg-info/SOURCES.txt’
reading manifest template ‘MANIFEST.in’
no previously-included directories found matching ‘v2’
no previously-included directories found matching ‘docsite’
no previously-included directories found matching ‘ticket_stubs’
no previously-included directories found matching ‘packaging’
no previously-included directories found matching ‘test’
no previously-included directories found matching ‘hacking’
warning: no previously-included files found matching ‘lib/ansible/modules/core/.git*’
warning: no previously-included files found matching ‘lib/ansible/modules/extras/.git*’
no previously-included directories found matching ‘lib/ansible/modules/core/.git’
no previously-included directories found matching ‘lib/ansible/modules/extras/.git’
writing manifest file ‘lib/ansible.egg-info/SOURCES.txt’
Setting up Ansible to run out of checkout…
PATH=/home/user/git/ansible/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
PYTHONPATH=/home/user/git/ansible/lib:
MANPATH=/home/user/git/ansible/docs/man:
Remember, you may wish to specify your host file with -i
Done!
I created a bare minimum module file to use (confirmed it works on Ubuntu 16.04):
$ cat test.py
from ansible.module_utils.basic import AnsibleModule
def main():
module = AnsibleModule(
argument_spec = dict(
state = dict(default=‘present’, choices=[‘present’, ‘absent’]),
name = dict(required=True),
enabled = dict(required=True, type=‘bool’),
something = dict(aliases=[‘whatever’])
)
)
module.exit_json(changed=True, something_else=12345)
if name == ‘main’:
main()
Running the test-module asks for options (as expected)
$ ./ansible/hacking/test-module
Usage: test-module -[options] (-h for help)
Options:
-h, --help show this help message and exit
-m MODULE_PATH, --module-path=MODULE_PATH
REQUIRED: full path of module source to execute
-a MODULE_ARGS, --args=MODULE_ARGS
module argument string
-D DEBUGGER, --debugger=DEBUGGER
path to python debugger (e.g. /usr/bin/pdb)
-I INTERPRETER_TYPE=INTERPRETER_PATH, --interpreter=INTERPRETER_TYPE=INTERPRETER_PATH
path to interpreter to use for this module (e.g.
ansible_python_interpreter=/usr/bin/python)
-c, --check run the module in check mode
-n, --noexecute do not run the resulting module
-o FILENAME, --output=FILENAME
Filename for resulting module
However, when running the module with test-module (with and without the --interpreter flag present), results in the following error:
$ ./ansible/hacking/test-module -m test.py --interpreter=ansible_python_interpreter=/usr/bin/python2
Traceback (most recent call last):
File “./ansible/hacking/test-module”, line 245, in
main()
File “./ansible/hacking/test-module”, line 227, in main
(modfile, modname, module_style) = boilerplate_module(options.module_path, options.module_args, options.interpreter, options.check, options.filename)
File “./ansible/hacking/test-module”, line 149, in boilerplate_module
if module_style == ‘new’ and ‘ANSIBALLZ_WRAPPER = True’ in module_data:
TypeError: a bytes-like object is required, not ‘str’
From what I read it sounds like it’s a python3-related error, but overriding the interpreter I would assume would use python2.
Any insight into fixing this would be great.
Andrew