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

AttributeError: 'bool' object has no attribute 'rfind' when sshkeys set to False #36

Closed
djowett opened this issue Aug 24, 2016 · 7 comments

Comments

@djowett
Copy link
Contributor

djowett commented Aug 24, 2016

I'm on Ansible 2.1 (Ubuntu 16.04) and I find the following error when I try to use this role.
I've tried setting odoo_user_sshkeys: to False, 0, "False", but I just get variations on the same error.

TASK [sebalix.odoo : Set SSH public keys for the Odoo user] ********************
task path: /etc/ansible/roles/sebalix.odoo/tasks/install_extra.yml:3
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 93, in run
    items = self._get_loop_items()
  File "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 195, in _get_loop_items
    items = self._shared_loader_obj.lookup_loader.get(self._task.loop, loader=self._loader, templar=templar).run(terms=loop_terms, variables=self._job_vars, wantlist=True)
  File "/usr/lib/python2.7/dist-packages/ansible/plugins/lookup/fileglob.py", line 33, in run
    term_file = os.path.basename(term)
  File "/usr/lib/python2.7/posixpath.py", line 114, in basename
    i = p.rfind('/') + 1
AttributeError: 'bool' object has no attribute 'rfind'

fatal: [eagle]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}
@sebalix
Copy link
Collaborator

sebalix commented Aug 24, 2016

Yes, I encounter this one too, so I'm stuck on Ansible 2.0 for the moment. I'm busy right now, but PRs are welcome!

@djowett
Copy link
Contributor Author

djowett commented Aug 24, 2016

Ah, glad it's not just me....

On further investigation (this doc)[http://ansible-docs.readthedocs.io/zh/stable-2.0/rst/playbooks_loops.html#standard-loops] says:

Also be aware that when combining when with with_items (or any other loop statement), the when statement is processed separately for each item. See The When Statement for an example.

and (this page)[http://ansible-docs.readthedocs.io/zh/stable-2.0/rst/playbooks_conditionals.html#applying-when-to-roles-and-includes] says

Note that if you have several tasks that all share the same conditional statement, you can affix the conditional to a task include statement as below. All the tasks get evaluated, but the conditional is applied to each and every task

Which adds up to the with_fileglob clause in install_extra.yml getting executed before the when clause in install.yml

@djowett
Copy link
Contributor Author

djowett commented Aug 24, 2016

You could try this for install_extra.yml

---

# Use a block so that the when clause gets evaluated for the whole 
# statement not every individual item within it
- name: Set SSH Keys
  set_fact:
    sshkeys: "{{ odoo_user_sshkeys }}"

- block:

    - name: Set SSH public keys for the Odoo user
      authorized_key: user={{ odoo_user }}
                      key="{{ lookup('file', item) }}"
      with_fileglob:
        - "{{ sshkeys }}"
  when: sshkeys is defined and sshkeys != False
  tags:
    - odoo_ssh

It's not a long term fix though as it gets this warning if odoo_user_sshkeys is set to False

TASK [sebalix.odoo : Set SSH public keys for the Odoo user] ********************
task path: /etc/ansible/roles/sebalix.odoo/tasks/install_extra.yml:11
[DEPRECATION WARNING]: Skipping task due to undefined Error, in the future this will be a fatal error.: 'sshkeys' is undefined.
This feature will be removed in a future 
release. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
skipping: [eagle] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true}

See also ansible/ansible#14383

djowett added a commit to jowent/ansible-odoo that referenced this issue Aug 25, 2016
djowett added a commit to jowent/ansible-odoo that referenced this issue Aug 25, 2016
…ote also removing unnecessary 'odoo_ssh' tag
@sebalix
Copy link
Collaborator

sebalix commented Sep 1, 2016

This was working well on Ansible 2.1.0.0 (all tests were green when I added the support for the 2.1 release), but now the tests fails since Ansible 2.1.1.0.
I don't know if it is a regression or a desired behavior of Ansible. For readers, a "quick and dirty" fix for this bug is:

# pip install ansible==2.1.0.0 --upgrade

@djowett
Copy link
Contributor Author

djowett commented Sep 2, 2016

@sebalix I'm happy to wait and see what next Ansible gives us, then if it's still an issue you can maybe set up a branch for higher versions.

@sebalix
Copy link
Collaborator

sebalix commented Sep 2, 2016

I just need time to resolve this issue, you give me some idea about this block: directive. If we need to drop the compatibility with older versions and supports Ansible >= 2.1.1.0 it is fine.

sebalix pushed a commit to sebalix/ansible-odoo that referenced this issue Dec 17, 2016
sebalix pushed a commit to sebalix/ansible-odoo that referenced this issue Dec 17, 2016
…ote also removing unnecessary 'odoo_ssh' tag
sebalix added a commit to sebalix/ansible-odoo that referenced this issue Dec 18, 2016
@sebalix
Copy link
Collaborator

sebalix commented Dec 18, 2016

Hi @djowett ,
I think the fix is as simple as that: set the default value of odoo_user_sshkeys with an empty string.
It remains the bug related to PostgreSQL tasks, but your PR almost fix it, it'll be fixed soon (today I think).

sebalix added a commit to sebalix/ansible-odoo that referenced this issue Oct 19, 2017
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