new module: TypeError: 'NoneType' object is not iterable

im trying to programm a new ansible module. while testing i get the following error.

Traceback (most recent call last):
File “/tmp/ansible_EHl4xq/ansible_module_aix_stanza.py”, line 276, in
main()
File “/tmp/ansible_EHl4xq/ansible_module_aix_stanza.py”, line 257, in main
(changed, backup_file, diff, msg) = do_stanza(module, path, stanza, options, state, backup, create)
TypeError: ‘NoneType’ object is not iterable

i cannot see whats the particular problem here…any hints?

`
#!/usr/bin/python

-- coding: utf-8 --

from future import absolute_import, division, print_function
metaclass = type

ANSIBLE_METADATA = {
‘metadata_version’: ‘1.1’,
‘status’: [‘preview’],
‘supported_by’: ‘community’
}

DOCUMENTATION = ‘’’

Gruess Gott Christian,

what I did while debugging my ansible module is .

export ANSIBLE_KEEP_REMOTE_FILES=1
run ansible scipt /playbook etc

ansible-playbook -i /tmp/i /home/mslebodn/lbuild/pb/vcs_update.yml

and on target machine , find prepared ansible module and run it with pdb

[ans@r7_ms_vcs1 ~]$ find . -name ‘veritas
./.ansible/tmp/ansible-tmp-1542277938.32-134723917146469/veritas.py
[ans@r7_ms_vcs1 ~]$ ./.ansible/tmp/ansible-tmp-1542277938.32-134723917146469/veritas.py explode
Module expanded into:
/home/ans/.ansible/tmp/ansible-tmp-1542277938.32-134723917146469/debug_dir
[ans@r7_ms_vcs1 ~]$ cd /home/ans/.ansible/tmp/ansible-tmp-1542277938.32-134723917146469/debug_dir
[ans@r7_ms_vcs1 debug_dir]$ python -m pdb ansible_module_veritas.py args

št 15. 11. 2018 o 11:26 <christian.tremel@itsv.at> napísal(a):

No very enlightening…!? Any glue how to translate this gibberish into something comprehensible?

TypeError: “‘NoneType’ object is not iterable”

/root/.ansible/tmp/ansible-tmp-1542279389.38-35472470665900/debug_dir/ansible_module_aix_stanza.py(276)()

→ main()

(Pdb)

–Return–

/root/.ansible/tmp/ansible-tmp-1542279389.38-35472470665900/debug_dir/ansible_module_aix_stanza.py(276)()->None

→ main()

(Pdb)

TypeError: “‘NoneType’ object is not iterable”

(1)()->None

(Pdb)

–Return–

(1)()->None

(Pdb)

Traceback (most recent call last):

File “/usr/lib64/python2.7/pdb.py”, line 1314, in main

pdb._runscript(mainpyfile)

File “/usr/lib64/python2.7/pdb.py”, line 1233, in _runscript

self.run(statement)

File “/usr/lib64/python2.7/bdb.py”, line 400, in run

exec cmd in globals, locals

File “”, line 1, in

File “ansible_module_aix_stanza.py”, line 276, in

main()

File “ansible_module_aix_stanza.py”, line 257, in main

(changed, backup_file, diff, msg) = do_stanza(module, path, stanza, options, state, backup, create)

TypeError: ‘NoneType’ object is not iterable

Uncaught exception. Entering post mortem debugging

Running ‘cont’ or ‘step’ will restart the program

/root/.ansible/tmp/ansible-tmp-1542279389.38-35472470665900/debug_dir/ansible_module_aix_stanza.py(257)main()

→ (changed, backup_file, diff, msg) = do_stanza(module, path, stanza, options, state, backup, create)

(Pdb) l

252 options = module.params[‘options’]

253 state = module.params[‘state’]

254 backup = module.params[‘backup’]

255 create = module.params[‘create’]

256

257 → (changed, backup_file, diff, msg) = do_stanza(module, path, stanza, options, state, backup, create)

258

259 if not module.check_mode and os.path.exists(path):

260 file_args = module.load_file_common_arguments(module.params)

261 changed = module.set_fs_attributes_if_different(file_args, changed)

262

(Pdb)

________________________________­­­

Christian Tremel
IT-Services der Sozialversicherung GmbH

Rechenzentrum

AIX Systemadministrator

Gruberstraße 77

A – 4021 Linz

T: +43 (0)50124 844 1266

M: +43 (0)664 88661266

christian.tremel@itsv.at

www.itsv.at

https://plattform.sozvers.at/Lists/Schlagzeilen/Attachments/493/CIS-Logo-Signatur.png

A quick look seems to indicate that do_stanza may sometimes return None due to the indentation of the return at the bottom.

You would need to ensure that do_stanza always returns the tuple you expect.

(attachments)

image001.png
image001.png

The problem was indeed the wrong indentation oft he last return…thanx matt/marek for your help!

root@lpgaixmgmtlx01:/etc/ansible/aix>ansible-playbook stanza_test.yml -vvv

ansible-playbook 2.6.3

config file = /etc/ansible/aix/ansible.cfg

configured module search path = [u’/root/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]

ansible python module location = /usr/lib/python2.7/site-packages/ansible

executable location = /usr/bin/ansible-playbook

python version = 2.7.5 (default, May 31 2018, 09:45:54) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]

Using /etc/ansible/aix/ansible.cfg as config file

Parsed /etc/ansible/aix/dyninv/inventory.py inventory source with script plugin

PLAYBOOK: stanza_test.yml *************************************************************************************************************************************************************************************

1 plays in stanza_test.yml

PLAY [testme] *************************************************************************************************************************************************************************************************

META: ran handlers

TASK [stanza test] ********************************************************************************************************************************************************************************************

task path: /etc/ansible/aix/stanza_test.yml:7

<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root

<127.0.0.1> EXEC /bin/sh -c ‘echo ~root && sleep 0’

<127.0.0.1> EXEC /bin/sh -c ‘( umask 77 && mkdir -p “echo /root/.ansible/tmp/ansible-tmp-1542371918.99-53757181251403” && echo ansible-tmp-1542371918.99-53757181251403=“echo /root/.ansible/tmp/ansible-tmp-1542371918.99-53757181251403” ) && sleep 0’

Using module file /usr/lib/python2.7/site-packages/ansible/modules/files/aix_stanza.py

<127.0.0.1> PUT /root/.ansible/tmp/ansible-local-9944sl6I9w/tmpA9NMKl TO /root/.ansible/tmp/ansible-tmp-1542371918.99-53757181251403/aix_stanza.py

<127.0.0.1> EXEC /bin/sh -c ‘chmod u+x /root/.ansible/tmp/ansible-tmp-1542371918.99-53757181251403/ /root/.ansible/tmp/ansible-tmp-1542371918.99-53757181251403/aix_stanza.py && sleep 0’

<127.0.0.1> EXEC /bin/sh -c ‘/usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1542371918.99-53757181251403/aix_stanza.py && sleep 0’

changed: [localhost] => {

“changed”: true,

“diff”: {

“after”: “”,

“after_header”: “/root/stanza_test (content)”,

“before”: “”,

“before_header”: “/root/stanza_test (content)”

},

“gid”: 0,

“group”: “root”,

“invocation”: {

“module_args”: {

“attributes”: null,

“backup”: false,

“content”: null,

“create”: true,

“delimiter”: null,

“dest”: “/root/stanza_test”,

“directory_mode”: null,

“follow”: false,

“force”: null,

“group”: null,

“mode”: null,

“options”: {

“SYSTEM”: “LDAP”,

“bla”: “blaa”,

“registry”: “LDAP”

},

“owner”: null,

“path”: “/root/stanza_test”,

“regexp”: null,

“remote_src”: null,

“selevel”: null,

“serole”: null,

“setype”: null,

“seuser”: null,

“src”: null,

“stanza”: “fideloper22”,

“state”: “present”,

“unsafe_writes”: null

}

},

“mode”: “0644”,

“owner”: “root”,

“path”: “/root/stanza_test”,

“size”: 103,

“state”: “file”,

“uid”: 0

}

MSG:

stanza and option added

META: ran handlers

META: ran handlers

________________________________­­­

Christian Tremel
IT-Services der Sozialversicherung GmbH

Rechenzentrum

AIX Systemadministrator

Gruberstraße 77

A – 4021 Linz

T: +43 (0)50124 844 1266

M: +43 (0)664 88661266

christian.tremel@itsv.at

www.itsv.at

https://plattform.sozvers.at/Lists/Schlagzeilen/Attachments/493/CIS-Logo-Signatur.png