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

scaleway_secret_version: cannot get a secret with example in doc #16

Open
HanXHX opened this issue Nov 24, 2023 · 0 comments
Open

scaleway_secret_version: cannot get a secret with example in doc #16

HanXHX opened this issue Nov 24, 2023 · 0 comments
Assignees

Comments

@HanXHX
Copy link

HanXHX commented Nov 24, 2023

Hi,

I would like to get a secret value from a name.

When using your doc (https://github.com/scaleway/ansible/blob/2.5.0/plugins/modules/scaleway_secret_version.py#L95), i have this error:

My offending code:

        - name: SCALEWAY_SECRET_VERSION | Get SSH public key
          scaleway.scaleway.scaleway_secret_version:
            access_key:  "{{ scw_access_key }}"
            secret_key:  "{{ scw_secret_key }}"
            project_id: "{{ scw_project_id }}"
            region: "{{ scw_region }}"
            name: "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
          register: data_secret_version
          delegate_to: localhost
TASK [SCALEWAY_SECRET_VERSION | Get SSH public key] ****************************
task path: /homexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxx.yml:21
Read vars_file './xxxxxxxxxxxxxxxxxxxxx/scaleway.yml'
Using module file /home/xxxxxxxxxxxxxxxxxx/.cache/ansible-compat/0cb87f/collections/ansible_collections/scaleway/scaleway/plugins/modules/scaleway_secret_version.py
Pipelining is enabled.
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: xxxxxxxxxx
<localhost> EXEC /bin/sh -c '/home/xxxxxxxxxxxxxxxxxxxxxxxxx/venv/bin/python && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "<stdin>", line 107, in <module>
  File "<stdin>", line 99, in _ansiballz_main
  File "<stdin>", line 47, in invoke_module
  File "/usr/lib/python3.10/runpy.py", line 224, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_scaleway.scaleway.scaleway_secret_version_payload_6za0lq3b/ansible_scaleway.scaleway.scaleway_secret_version_payload.zip/ansible_collections/scaleway/scaleway/plugins/modules/scaleway_secret_version.py", line 389, in <module>
  File "/tmp/ansible_scaleway.scaleway.scaleway_secret_version_payload_6za0lq3b/ansible_scaleway.scaleway.scaleway_secret_version_payload.zip/ansible_collections/scaleway/scaleway/plugins/modules/scaleway_secret_version.py", line 385, in main
  File "/tmp/ansible_scaleway.scaleway.scaleway_secret_version_payload_6za0lq3b/ansible_scaleway.scaleway.scaleway_secret_version_payload.zip/ansible_collections/scaleway/scaleway/plugins/modules/scaleway_secret_version.py", line 320, in core
  File "/tmp/ansible_scaleway.scaleway.scaleway_secret_version_payload_6za0lq3b/ansible_scaleway.scaleway.scaleway_secret_version_payload.zip/ansible_collections/scaleway/scaleway/plugins/modules/scaleway_secret_version.py", line 164, in create
AttributeError: 'NoneType' object has no attribute 'encode'
fatal: [golden-image -> localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"<stdin>\", line 107, in <module>\n  File \"<stdin>\", line 99, in _ansiballz_main\n  File \"<stdin>\", line 47, in invoke_module\n  File \"/usr/lib/python3.10/runpy.py\", line 224, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.10/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.10/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_scaleway.scaleway.scaleway_secret_version_payload_6za0lq3b/ansible_scaleway.scaleway.scaleway_secret_version_payload.zip/ansible_collections/scaleway/scaleway/plugins/modules/scaleway_secret_version.py\", line 389, in <module>\n  File \"/tmp/ansible_scaleway.scaleway.scaleway_secret_version_payload_6za0lq3b/ansible_scaleway.scaleway.scaleway_secret_version_payload.zip/ansible_collections/scaleway/scaleway/plugins/modules/scaleway_secret_version.py\", line 385, in main\n  File \"/tmp/ansible_scaleway.scaleway.scaleway_secret_version_payload_6za0lq3b/ansible_scaleway.scaleway.scaleway_secret_version_payload.zip/ansible_collections/scaleway/scaleway/plugins/modules/scaleway_secret_version.py\", line 320, in core\n  File \"/tmp/ansible_scaleway.scaleway.scaleway_secret_version_payload_6za0lq3b/ansible_scaleway.scaleway.scaleway_secret_version_payload.zip/ansible_collections/scaleway/scaleway/plugins/modules/scaleway_secret_version.py\", line 164, in create\nAttributeError: 'NoneType' object has no attribute 'encode'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

While reading the source code, I think the main problem is https://github.com/scaleway/ansible/blob/2.5.0/plugins/modules/scaleway_secret_version.py#L337 The default value for state should be access. Or maybe fix the doc?

To bypass this issue, this updated code works:

        - name: SCALEWAY_SECRET_VERSION | Get SSH public key
          scaleway.scaleway.scaleway_secret_version:
            access_key:  "{{ scw_access_key }}"
            secret_key:  "{{ scw_secret_key }}"
            project_id: "{{ scw_project_id }}"
            region: "{{ scw_region }}"
            name: "xxxxxxxxxxxxxxxxxxxxxxx"
            state: "access"
          register: data_secret_version
          delegate_to: localhost

Other infos:

Ansible version: 2.15.6
Scaleway collection version: 2.5.0
Ansible Molecule version: 5.0.1
Python version: 3.10 (Ubuntu 22.04)

Best regards,

Emilien Mantel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants