Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken check mode in github_key module #9185

Closed
1 task done
tomcperry opened this issue Nov 24, 2024 · 2 comments · Fixed by #9186
Closed
1 task done

Broken check mode in github_key module #9185

tomcperry opened this issue Nov 24, 2024 · 2 comments · Fixed by #9186
Labels
bug This issue/PR relates to a bug has_pr module module plugins plugin (any type) traceback

Comments

@tomcperry
Copy link
Contributor

Summary

community.general.github_key fails when run in check mode (eg, when using ansible-playbook --check ...)

When running without the check flag, the module works fine.
Reviewing the code, I believe this was introduced in PR #8222

Specifically, here:

'created_at': datetime.strftime(now_t, '%Y-%m-%dT%H:%M:%SZ'),

I don't have a python environment handy, but I am pretty sure this should be changed to:

'created_at': datetime.datetime.strftime(now_t, '%Y-%m-%dT%H:%M:%SZ'),

Issue Type

Bug Report

Component Name

module is github_key.py

Ansible Version

ansible [core 2.16.3]
  config file = None
  configured module search path = ['/home/tom/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/tom/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.12.3 (main, Nov  6 2024, 18:32:19) [GCC 13.2.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Community.general Version

Collection        Version
----------------- -------
community.general 10.0.1 

Configuration

n/a

OS / Environment

Ubuntu 24.04

Steps to Reproduce

Given a playbook with this task:

  - name: Add ssh key to github
    become: true
    community.general.github_key:
      name: "{{ key_name }}"
      token: "{{ gh_token }}"
      pubkey: "{{ pubkey }}"
      state: present

it works fine when running ansible-playbook playbook.yml
But, if it is run with check mode (ie, ansible-playbook --check playbook.yml) then a python exception is generated (see below for error)

Expected Results

Expected to show that a change would occur without the error/exception

Actual Results

TASK [Add ssh key to github] *******************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: module 'datetime' has no attribute 'strftime'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/tom/.ansible/tmp/ansible-tmp-1732488395.5338001-12323-276562370367174/AnsiballZ_github_key.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/tom/.ansible/tmp/ansible-tmp-1732488395.5338001-12323-276562370367174/AnsiballZ_github_key.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/tom/.ansible/tmp/ansible-tmp-1732488395.5338001-12323-276562370367174/AnsiballZ_github_key.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.github_key', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.github_key', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/tmp/ansible_community.general.github_key_payload_k4s7yu7c/ansible_community.general.github_key_payload.zip/ansible_collections/community/general/plugins/modules/github_key.py\", line 260, in <module>\n  File \"/tmp/ansible_community.general.github_key_payload_k4s7yu7c/ansible_community.general.github_key_payload.zip/ansible_collections/community/general/plugins/modules/github_key.py\", line 251, in main\n  File \"/tmp/ansible_community.general.github_key_payload_k4s7yu7c/ansible_community.general.github_key_payload.zip/ansible_collections/community/general/plugins/modules/github_key.py\", line 210, in ensure_key_present\n  File \"/tmp/ansible_community.general.github_key_payload_k4s7yu7c/ansible_community.general.github_key_payload.zip/ansible_collections/community/general/plugins/modules/github_key.py\", line 165, in create_key\nAttributeError: module 'datetime' has no attribute 'strftime'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module plugins plugin (any type) traceback labels Nov 24, 2024
@felixfontein felixfontein added backport-8 Automatically create a backport for the stable-8 branch backport-9 Automatically create a backport for the stable-9 branch backport-10 Automatically create a backport for the stable-10 branch and removed backport-8 Automatically create a backport for the stable-8 branch backport-9 Automatically create a backport for the stable-9 branch backport-10 Automatically create a backport for the stable-10 branch labels Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug has_pr module module plugins plugin (any type) traceback
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants