community.aws icon indicating copy to clipboard operation
community.aws copied to clipboard

iam_role_info - Add new preserve_case option

Open Razique opened this issue 3 years ago • 6 comments

SUMMARY

Add a new preserve_case option to the iam_role_info module per #551. Allows users to get valid data that the be reused "as is".

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

iam_role_info

ADDITIONAL INFORMATION

I have initially attempted to use the camel_dict_to_snake_dict method with its ignore_list option, however, this only ignore the values, not the keys. The snact_dict_to_camel_dict method seems to be broken, it fails with the following message (on both Python 3.8 and Python 3.9)

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: function missing required argument 'year' (pos 1)

fatal: [testhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"<stdin>\", line 121, in 
<module>\n  File \"<stdin>\", line 113, in _ansiballz_main\n  File \"<stdin>\", line 61, in invoke_module\n  File \"/usr/lib/python3.8
/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File 
\"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File 
\"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_iam_role_info_payload_4milvilg/ansible_iam_role_info_payload.zip/ansible_collections/community/aws/plugins
/modules/iam_role_info.py\", line 269, in <module>\n  File \"/tmp/ansible_iam_role_info_payload_4milvilg/ansible_iam_role_info_payload.zip/ansible_collections/community/aws/plugins/modules/iam_role_info.py\", line 265, in
main\n  File \"/tmp/ansible_iam_role_info_payload_4milvilg/ansible_iam_role_info_payload.zip/ansible_collections/community/aws/plugins/modules/iam_role_info.py\", line 246, in describe_iam_roles\n  
File \"/tmp/ansible_iam_role_info_payload_4milvilg/ansible_iam_role_info_payload.zip/ansible_collections/community
/aws/plugins/modules/iam_role_info.py\", line 246, in <listcomp>\n  File \"/tmp/ansible_iam_role_info_payload_4milvilg
/ansible_iam_role_info_payload.zip/ansible/module_utils/common/dict_transformations.py\", line 76, in 
snake_dict_to_camel_dict\n  File \"/tmp/ansible_iam_role_info_payload_4milvilg/ansible_iam_role_info_payload.zip/ansible
/module_utils/common/dict_transformations.py\", line 68, in camelize\n  File \"/tmp/ansible_iam_role_info_payload_4milvilg
/ansible_iam_role_info_payload.zip/ansible/module_utils/common/dict_transformations.py\", line 65, in camelize\n

TypeError: function missing required argument 'year' (pos 1)\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Before

- name: find all existing IAM roles
  community.aws.iam_role_info:
  register: result

After

- name: find all existing IAM roles and preserve casing
  community.aws.iam_role_info:
    preserve_case: true
  register: result

Razique avatar Mar 12 '22 02:03 Razique

cc @jillr @markuman @s-hertel @tremble click here for bot help

ansibullbot avatar Mar 12 '22 02:03 ansibullbot

Looks like there are some errors.

ansible-galaxy-importer

'community.aws.wafv2_web_acl_info"' 'returncode="1"' 'b'\''ERROR!' 
module community.aws.aws_acm missing documentation '(or' could not parse 'documentation):'
unknown 'doc_fragment(s)' in file /tmp/tmpy5fvk3gt/ansible_collections/community/aws/plugins/\
modules/aws_acm.py: amazon.aws.aws,

ansible-test-sanity-docker-level:

ERROR: Host <ansible_test._internal.host_profiles.DockerProfile object at 0x7ff8a3efd790> job failed: Expecting value: line 1 column 1 (char 0)
  File "/home/zuul/venv/lib/python3.8/site-packages/ansible_test/_internal/provisioning.py", line 190, in dispatch_jobs
    thread.wait_for_result()
  File "/home/zuul/venv/lib/python3.8/site-packages/ansible_test/_internal/thread.py", line 44, in wait_for_result
    raise exception[1].with_traceback(exception[2])
  File "/home/zuul/venv/lib/python3.8/site-packages/ansible_test/_internal/thread.py", line 31, in run
    self._result.put((self.action(), None))
  File "/home/zuul/venv/lib/python3.8/site-packages/ansible_test/_internal/provisioning.py", line 128, in provision
    profile.provision()
  File "/home/zuul/venv/lib/python3.8/site-packages/ansible_test/_internal/host_profiles.py", line 338, in provision
    container = run_support_container(
  File "/home/zuul/venv/lib/python3.8/site-packages/ansible_test/_internal/containers.py", line 184, in run_support_container
    docker_pull(args, image)
  File "/home/zuul/venv/lib/python3.8/site-packages/ansible_test/_internal/docker_util.py", line 263, in docker_pull
    if docker_image_exists(args, image):
  File "/home/zuul/venv/lib/python3.8/site-packages/ansible_test/_internal/docker_util.py", line 500, in docker_image_exists
    docker_command(args, ['image', 'inspect', image], capture=True)
  File "/home/zuul/venv/lib/python3.8/site-packages/ansible_test/_internal/docker_util.py", line 551, in docker_command
    if command[0] == 'podman' and _get_podman_remote():
  File "/home/zuul/venv/lib/python3.8/site-packages/ansible_test/_internal/thread.py", line 59, in wrapper
    return func(*args, **kwargs)
  File "/home/zuul/venv/lib/python3.8/site-packages/ansible_test/_internal/util.py", line 113, in cache_func
    value = storage[None] = func()
  File "/home/zuul/venv/lib/python3.8/site-packages/ansible_test/_internal/docker_util.py", line 169, in _get_podman_remote
    podman_host = get_podman_default_hostname()
  File "/home/zuul/venv/lib/python3.8/site-packages/ansible_test/_internal/thread.py", line 59, in wrapper
    return func(*args, **kwargs)
  File "/home/zuul/venv/lib/python3.8/site-packages/ansible_test/_internal/util.py", line 113, in cache_func
    value = storage[None] = func()
  File "/home/zuul/venv/lib/python3.8/site-packages/ansible_test/_internal/docker_util.py", line 145, in get_podman_default_hostname
    connections = json.loads(stdout)
  File "/usr/lib64/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None

ansible-test-sanity-docker-milestone:

Building wheels for collected packages: yamllint
  Building wheel for yamllint (setup.py): started
  Building wheel for yamllint (setup.py): finished with status 'error'
  ERROR: Command errored out with exit status 1:
   command: /root/.ansible/test/venv/sanity.yamllint/3.8/c8d3ca72/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-tcv05bng/yamllint/setup.py'"'"'; __file__='"'"'/tmp/pip-install-tcv05bng/yamllint/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-78z9o8fw
       cwd: /tmp/pip-install-tcv05bng/yamllint/
  Complete output (6 lines):
  usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: setup.py --help [cmd1 cmd2 ...]
     or: setup.py --help-commands
     or: setup.py cmd --help
  
  error: invalid command 'bdist_wheel'

I see that I can fix the ansible-test-sanity-docker-stable-2.12 one (I didn't set a default value for the new parameter)

Razique avatar Apr 01 '22 01:04 Razique

I have fixed all the issues I could on my end. There are some errors in the CI jobs but I can't do much there. Thanks for your help.

Razique avatar Apr 01 '22 03:04 Razique

Thanks for this @Razique

I'm Closing this in favour of #1692 it's only the policy file we shouldn't be mangling and we now have a policy about how to deprecate/change values https://github.com/ansible-collections/amazon.aws/blob/main/docs/docsite/rst/dev_guidelines.rst#deprecating-return-values

tremble avatar Feb 02 '23 12:02 tremble