0

Having an issue with a test playbook I am working on to pull various secrets from our company 1Password vault.

I can pull secrets via the 1Pass CLI so its not a permissions / network / application issue. Just something with my sample play.

---
- name: 1Password testing
  hosts: $testHost
  connection: local
  gather_facts: false
  pre_tasks:
    - name: Fixing 1Pass module bug...
      file:
        state: touch
        path: "{{ '~/.op/config' | expanduser }}"
        mode: 0700
      run_once: true
    - name: Import 1Password secrets...
      include_vars: /etc/ansible/1password.yml
    - name: Retrieve API keys...
      community.general.onepassword_info:
        auto_login:
          master_password: '{{  account_password  }}'
        search_terms:
          - name: "{{  inventory_hostname  }}"
            field: "credential"
            vault: "my_vault"
        cli_path: "~/.op/config"
      delegate_to: localhost
      register: api_key

When running, I am getting a error on the task that follows:

TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

I understand what its trying to say. I have some kind of mis-matched data type, but I don't understand which field. The log does not appear to be descriptive enough, even with -vvvvv flagged.

Full output:

The full traceback is:
Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-tmp-1684603988.409842-4767-16415303489901/AnsiballZ_onepassword_info.py", line 102, in <module>
    _ansiballz_main()
  File "/root/.ansible/tmp/ansible-tmp-1684603988.409842-4767-16415303489901/AnsiballZ_onepassword_info.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/root/.ansible/tmp/ansible-tmp-1684603988.409842-4767-16415303489901/AnsiballZ_onepassword_info.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.onepassword_info', init_globals=None, run_name='__main__', alter_sys=True)
  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_community.general.onepassword_info_payload_qzgnswsl/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py", line 390, in <module>
  File "/tmp/ansible_community.general.onepassword_info_payload_qzgnswsl/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py", line 384, in main
  File "/tmp/ansible_community.general.onepassword_info_payload_qzgnswsl/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py", line 351, in run
  File "/tmp/ansible_community.general.onepassword_info_payload_qzgnswsl/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py", line 342, in assert_logged_in
  File "/tmp/ansible_community.general.onepassword_info_payload_qzgnswsl/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py", line 308, in get_token
  File "/usr/lib/python3.10/genericpath.py", line 30, in isfile
    st = os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
$targetHost | FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1684603988.409842-4767-16415303489901/AnsiballZ_onepassword_info.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1684603988.409842-4767-16415303489901/AnsiballZ_onepassword_info.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1684603988.409842-4767-16415303489901/AnsiballZ_onepassword_info.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.onepassword_info', init_globals=None, run_name='__main__', alter_sys=True)\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_community.general.onepassword_info_payload_qzgnswsl/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py\", line 390, in <module>\n  File \"/tmp/ansible_community.general.onepassword_info_payload_qzgnswsl/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py\", line 384, in main\n  File \"/tmp/ansible_community.general.onepassword_info_payload_qzgnswsl/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py\", line 351, in run\n  File \"/tmp/ansible_community.general.onepassword_info_payload_qzgnswsl/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py\", line 342, in assert_logged_in\n  File \"/tmp/ansible_community.general.onepassword_info_payload_qzgnswsl/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py\", line 308, in get_token\n  File \"/usr/lib/python3.10/genericpath.py\", line 30, in isfile\n    st = os.stat(path)\nTypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

This is for Ansible core 2.14.5 and community.general of 1.3.6 or 6.6.0 depending on the installation path according to the collection list.

New edit - 2023-05-22, response to mdaniel, try #2.

Output from "mode: 0600":

    An exception occurred during task execution. To see the full traceback, use -vvv. The error was: PermissionError: [Errno 13] Permission denied: '/root/.op/config'
$targetHost | FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1684811698.3200085-22036-163190884623241/AnsiballZ_onepassword_info.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1684811698.3200085-22036-163190884623241/AnsiballZ_onepassword_info.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1684811698.3200085-22036-163190884623241/AnsiballZ_onepassword_info.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.onepassword_info', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.onepassword_info', _modlib_path=modlib_path),\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_community.general.onepassword_info_payload_9bdub1uc/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py\", line 390, in <module>\n  File \"/tmp/ansible_community.general.onepassword_info_payload_9bdub1uc/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py\", line 384, in main\n  File \"/tmp/ansible_community.general.onepassword_info_payload_9bdub1uc/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py\", line 351, in run\n  File \"/tmp/ansible_community.general.onepassword_info_payload_9bdub1uc/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py\", line 346, in assert_logged_in\n  File \"/tmp/ansible_community.general.onepassword_info_payload_9bdub1uc/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py\", line 338, in assert_logged_in\n  File \"/tmp/ansible_community.general.onepassword_info_payload_9bdub1uc/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py\", line 202, in _run\n  File \"/usr/lib/python3.10/subprocess.py\", line 969, in __init__\n    self._execute_child(args, executable, preexec_fn, close_fds,\n  File \"/usr/lib/python3.10/subprocess.py\", line 1845, in _execute_child\n    raise child_exception_type(errno_num, err_msg, err_filename)\nPermissionError: [Errno 13] Permission denied: '/root/.op/config'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

Output from "mode: 0700"

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: OSError: [Errno 8] Exec format error: '/root/.op/config'
ATLAB-PF-FW | FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1684811717.592182-22110-137137656610529/AnsiballZ_onepassword_info.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1684811717.592182-22110-137137656610529/AnsiballZ_onepassword_info.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1684811717.592182-22110-137137656610529/AnsiballZ_onepassword_info.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.onepassword_info', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.onepassword_info', _modlib_path=modlib_path),\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_community.general.onepassword_info_payload_simtqqd8/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py\", line 390, in <module>\n  File \"/tmp/ansible_community.general.onepassword_info_payload_simtqqd8/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py\", line 384, in main\n  File \"/tmp/ansible_community.general.onepassword_info_payload_simtqqd8/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py\", line 351, in run\n  File \"/tmp/ansible_community.general.onepassword_info_payload_simtqqd8/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py\", line 346, in assert_logged_in\n  File \"/tmp/ansible_community.general.onepassword_info_payload_simtqqd8/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py\", line 338, in assert_logged_in\n  File \"/tmp/ansible_community.general.onepassword_info_payload_simtqqd8/ansible_community.general.onepassword_info_payload.zip/ansible_collections/community/general/plugins/modules/onepassword_info.py\", line 202, in _run\n  File \"/usr/lib/python3.10/subprocess.py\", line 969, in __init__\n    self._execute_child(args, executable, preexec_fn, close_fds,\n  File \"/usr/lib/python3.10/subprocess.py\", line 1845, in _execute_child\n    raise child_exception_type(errno_num, err_msg, err_filename)\nOSError: [Errno 8] Exec format error: '/root/.op/config'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}
Moridn
  • 35
  • 6
  • If I quickly look In the documentation, the only parameter that the module indeed expects as a path is `cli_path`: https://docs.ansible.com/ansible/latest/collections/community/general/onepassword_info_module.html. Now why is it complaining although it is not a required parameter is another question indeed. – β.εηοιτ.βε May 20 '23 at 19:07
  • 1
    Well, to your eyes the `-vvvvv` may not mean anything, but if it correctly provides the backtrace then it'll help us to help you. The other is that thanks to modern ansible, it's important that you provide the version of ansible _and_ any `ansible-galaxy` collections you're using. Don't put that info in the comments, instead please [edit your question](https://stackoverflow.com/posts/76296576/edit) and provide it – mdaniel May 20 '23 at 21:06
  • Edited. Added the detail you requested. – Moridn May 21 '23 at 00:03

1 Answers1

1

It's a bug in the contract between their module_utils.onepassword.OnePasswordConfig where they let the @property fall off the bottom of the method meaning it returns None, but the caller doesn't check for that

The best case would be them fixing that, but I'd guess the work-around for you is to ensure one of these 3 files exists

- file:
    state: touch
    path: "{{ '~/.op/config' | expanduser }}"
    mode: 0600
- debug:
    msg: now try your onepassword_info task
mdaniel
  • 31,240
  • 5
  • 55
  • 58
  • Alright. I have found a permissions issue in ~/.op/config that I fixed after removing / reinstalling / re-linking the 1Pass CLI installer. The file is now correctly created and in the home directory. But when I reran the play, I am getting something new. Adding the output to the original post, as I am over my character limit. – Moridn May 22 '23 at 15:47
  • While updating your post, please update the actual code you're using, since if you just hard-coded `/root/.op/config` that'd be a fine reason it wouldn't work, and doubly so with the `become:` values. Furthermore, that's a very straightforward error - so what troubleshooting have you already tried to resolve such a simple error yourself? – mdaniel May 22 '23 at 19:18
  • Yes, that was from earlier this morning before I could Google alot of it. This is a pet project of mine, and finding time is difficult during work hours. I noticed what you said earlier, because I remembered my path was not "/root/.op/config" and attempted to force the cli_path object to the correct path. On my attempt with permission 0600, I saw a permission error. I changed it to 700, thinking it may have needed execute rights, and got something different. Either way, I am super confused on where the "/root/.op/config" path is coming from as I do not use that path at all. – Moridn May 23 '23 at 03:19