viasite-ansible / ansible-role-zsh

Setup antigen with oh-my-zsh, powerlevel10k theme, fzf, autosuggestions, syntax-highlighting
https://habrahabr.ru/post/323496/
MIT License
346 stars 84 forks source link

ansible 2.13.1 ''str object'' has no attribute ''hotkey''' #62

Closed rparree closed 1 year ago

rparree commented 2 years ago

The role is throwing an error when running with Ansible 2.13.1:

fatal: [machine-06]: FAILED! => changed=false 
  msg: 'AnsibleUndefinedVariable: ''str object'' has no attribute ''hotkey'''

When i downgrade to 2.12.3 then it works again.

AritraWork97 commented 2 years ago

Same here.

popstas commented 2 years ago

Thank you, will check in next week.

numediaweb commented 2 years ago

I fixed it inside templates/zshrc.j2 with:

# hotkeys
{% for hotkey in zsh_hotkeys %}
    {% if 'hotkey' in hotkey and hotkey.hotkey != '' and (hotkey.bundle is not defined or hotkey.bundle in bundles_enabled) %}
        bindkey '{{ hotkey.hotkey }}' {{ hotkey.action }}
    {% endif %}
{% endfor %}

But facing other issues with bundles when using ubuntu-22-04-x64 release... Just removing the bundle section for now.

quantumfate commented 2 years ago

I created a pull request on this https://github.com/viasite-ansible/ansible-role-zsh/pull/64

quantumfate commented 2 years ago

this pull fixed more related issues https://github.com/viasite-ansible/ansible-role-zsh/pull/69

snowball77 commented 2 years ago

I tried the pull request, thank you @quantumfate . For me it works, without it the role is useless as it fails or produces incorrect outputs

SturmB commented 2 years ago

this pull fixed more related issues #69

This is the one. I manually applied the changes myself (I'm not sure how else to do it until the PR is approved and merged) and it works perfectly on Ubuntu 22.04.1.

Thank you, @quantumfate!

rparree commented 1 year ago

any progress on merging the PR?

staseek commented 1 year ago

Cool PR! Thank you. For hot fix without patching source code of role. You can add variable zsh_hotkeys

For example

      zsh_hotkeys:
        - { hotkey: '^r', action: 'fzf-history' }
        # with dependency of bundle
        - { hotkey: '`', action: autosuggest-accept, bundle: zsh-users/zsh-autosuggestions }

And after this action role from ansible-galaxy will work fine.

ThomasDalla commented 1 year ago

Still failing with Ansible 2.14.3.

TASK [viasite-ansible.zsh : Write .zshrc config] ********************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'str object' has no attribute 'hotkey'. 'str object' has no attribute 'hotkey'
fatal: [ryzen5]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'str object' has no attribute 'hotkey'. 'str object' has no attribute 'hotkey'"}

I did add zsh_hotkeys, no impact.

    zsh_hotkeys:
      - { hotkey: '^r', action: 'fzf-history' }
      - { hotkey: '^ ', action: autosuggest-accept, bundle: zsh-users/zsh-autosuggestions }

Full trace

The full traceback is:
Traceback (most recent call last):
  File "/home/username/.local/lib/python3.10/site-packages/ansible/template/__init__.py", line 987, in do_template
    res = self.environment.concat(rf)
  File "/home/username/.local/lib/python3.10/site-packages/ansible/template/native_helpers.py", line 88, in ansible_concat
    return ''.join([to_text(v) for v in nodes])
  File "/home/username/.local/lib/python3.10/site-packages/ansible/template/native_helpers.py", line 88, in <listcomp>
    return ''.join([to_text(v) for v in nodes])
  File "<template>", line 202, in root
  File "/usr/lib/python3.10/site-packages/jinja2/runtime.py", line 852, in _fail_with_undefined_error
    raise self._undefined_exception(self._undefined_message)
jinja2.exceptions.UndefinedError: 'str object' has no attribute 'hotkey'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/username/.local/lib/python3.10/site-packages/ansible/plugins/action/template.py", line 141, in run
    resultant = templar.do_template(template_data, preserve_trailing_newlines=True, escape_backslashes=False)
  File "/home/username/.local/lib/python3.10/site-packages/ansible/template/__init__.py", line 1021, in do_template
    raise AnsibleUndefinedVariable(e, orig_exc=e)
ansible.errors.AnsibleUndefinedVariable: 'str object' has no attribute 'hotkey'. 'str object' has no attribute 'hotkey'
fatal: [ryzen5]: FAILED! => {
    "changed": false,
    "msg": "AnsibleUndefinedVariable: 'str object' has no attribute 'hotkey'. 'str object' has no attribute 'hotkey'"
}
popstas commented 1 year ago

Fixed, thank you, sorry for a long ignoring.