Thanks to visit codestin.com
Credit goes to github.com

Skip to content

aix_filesystem.py - fail_json() missing msg=  #58609

@d-little

Description

@d-little
SUMMARY

When passed invalid data, a number of functions in lib/ansible/modules/system/aix_filesystem.py are running fail_json() without msg= on the error message itself, generating: TypeError: exit_json() takes exactly 1 argument (4 given) when attempting to fail.

ie:

def resize_fs(module, filesystem, size):
....
                module.fail_json("Failed to run chfs.", rc=rc, err=err)
....

def mount_fs(module, filesystem):
...
            module.fail_json("Failed to run mount.", rc=rc, err=err)
...

def unmount_fs(module, filesystem):
...
            module.fail_json("Failed to run unmount.", rc=rc, err=err)
...

To fulfil function requirements, kwargs should be:

def resize_fs(module, filesystem, size):
....
                module.fail_json(msg="Failed to run chfs.", rc=rc, err=err)
....

def mount_fs(module, filesystem):
...
            module.fail_json(msg="Failed to run mount.", rc=rc, err=err)
...

def unmount_fs(module, filesystem):
...
            module.fail_json(msg="Failed to run unmount.", rc=rc, err=err)
...
ISSUE TYPE
  • Bug Report
COMPONENT NAME

aix_filesystem.py

ANSIBLE VERSION
ansible 2.8.0
  config file = /etc/ansible/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 = /bin/ansible
  python version = 2.7.5 (default, Apr  9 2019, 14:30:50) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

CONFIGURATION
ANSIBLE_PIPELINING(/etc/ansible/ansible.cfg) = True
ANSIBLE_SSH_ARGS(/etc/ansible/ansible.cfg) = -o ForwardAgent=no
COMMAND_WARNINGS(/etc/ansible/ansible.cfg) = True
DEFAULT_BECOME(/etc/ansible/ansible.cfg) = True
DEFAULT_FORCE_HANDLERS(/etc/ansible/ansible.cfg) = True
DEFAULT_FORKS(/etc/ansible/ansible.cfg) = 50
DEFAULT_KEEP_REMOTE_FILES(env: ANSIBLE_KEEP_REMOTE_FILES) = True
DEFAULT_MANAGED_STR(/etc/ansible/ansible.cfg) = This file is managed by ansible - local changes will be lost! - Last Updated {{ now(fmt='%Y/%m/%d - %H:%M:%S %z(%Z)') }}
DEFAULT_REMOTE_USER(/etc/ansible/ansible.cfg) = root
DEFAULT_ROLES_PATH(/etc/ansible/ansible.cfg) = [u'/etc/ansible/roles/internal', u'/etc/ansible/roles/external']
DEFAULT_TRANSPORT(/etc/ansible/ansible.cfg) = ssh
DEPRECATION_WARNINGS(/etc/ansible/ansible.cfg) = True
RETRY_FILES_ENABLED(/etc/ansible/ansible.cfg) = True
SYSTEM_WARNINGS(/etc/ansible/ansible.cfg) = True
OS / ENVIRONMENT

AIX

STEPS TO REPRODUCE

Run module with the above invalid data, such as mounting a filesystem which does not exist.

ansible HOSTNAME -i /etc/ansible/test.ini -m aix_filesystem -a "filesystem=/mnt/exp1 state=mounted"
EXPECTED RESULTS

With a fix in place in mount_fs() :

        if rc != 0:
            module.fail_json(msg="Failed to run mount.", rc=rc, err=err)
{"msg": "Failed to run mount.", "failed": true, "rc": 1, "err": "mount: /mnt/exp1 is not a known file system\n", "invocation": {"module_args": {"size": null, "vg": null, "rm_mount_point": false, "auto_mount": true, "account_subsystem": false, "mount_group": null, "state": "mounted", "fs_type": "jfs2", "filesystem": "/mnt/exp1", "device": "lv_exp1", "nfs_server": null, "attributes": ["agblksize='4096'", "isnapshot='no'"], "permissions": "rw"}}}
ACTUAL RESULTS

Using current code:

        if rc != 0:
            print(err)
            module.fail_json("Failed to run mount.", rc=rc, err=err)
Traceback (most recent call last):
  File "__main__.py", line 579, in <module>
    main()
  File "__main__.py", line 561, in main
    result['changed'], result['msg'] = mount_fs(module, filesystem)
  File "__main__.py", line 430, in mount_fs
    module.fail_json("Failed to run mount.", rc=rc, err=err)
TypeError: fail_json() takes exactly 1 argument (4 given)

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects_2.8This issue/PR affects Ansible v2.8aixAIX communitybugThis issue/PR relates to a bug.moduleThis issue/PR relates to a module.support:communityThis issue/PR relates to code supported by the Ansible community.systemSystem categorytracebackThis issue/PR includes a traceback.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions