Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

Variable homebrew_uninstalled_packages is undefined #66

Closed
mikesouza opened this issue Mar 20, 2017 · 4 comments
Closed

Variable homebrew_uninstalled_packages is undefined #66

mikesouza opened this issue Mar 20, 2017 · 4 comments

Comments

@mikesouza
Copy link
Contributor

mikesouza commented Mar 20, 2017

ansible-role-homebrew_uninstalled_packages

I think this is a bug, but I'm not sure if it's something with my particular ansible configuration (default) or what. Based on commits 50c72f2 and b5bb8f5, I can't tell whether it's just me getting this error or not.

In my existing and new playbooks dependent on this role, I MUST define the variable homebrew_uninstalled_packages: [] else I get the error above.

Anyways, the simple fix is to uncomment the homebrew_uninstalled_packages variable in defaults/main.yml. I'm just unsure if there was a reason for commenting it out in the first place.

Let me know if you need any further details. Thanks.

@mikesouza mikesouza changed the title Variable homebrew_uninstalled_packages is not defined Variable homebrew_uninstalled_packages is undefined Mar 20, 2017
@elliotweiser
Copy link
Collaborator

IIRC, Ansible 2.0+ dislikes undefined variables, which seems to obviate the is defined check. My guess is the "best" (or at least easiest) fix is to uncomment the offending variable in defaults/main.yml, thus defining it. Sane default; easily overridden.

@geerlingguy
Copy link
Owner

There's another way of defining that when condition, though... I can't recall right now and can't look up in my recent commits to other roles, but you basically have to do two checks to see if it's defined and has a value—I think. It might be safer/more sane, otherwise I'm okay with just uncommenting that default var if it doesn't cause any other issues.

mikesouza added a commit to mikesouza/ansible-role-homebrew that referenced this issue Mar 20, 2017
@mikesouza mikesouza mentioned this issue Mar 20, 2017
@mikesouza
Copy link
Contributor Author

mikesouza commented Mar 20, 2017

Thanks for the quick responses and feedback.

I've determined the root cause of the failed task; the with_items: {{ homebrew_uninstalled_packages }} is evaluated before the when: homebrew_uninstalled_packages is defined clause. This is intended behavior (See ansible/ansible#13950), and one solution is to change it to with_items: {{ homebrew_uninstalled_packages|default([]) }}.

However, IMO the better solution is to uncomment the line in defaults/main.yml and remove the when clause from the task altogether, for the following reasons:

  • From the POV of someone new using this role, it's nice to be able to just look in the defaults/main.yml to see all available variables and defaults, especially when every other variable is defined and defaulted in this file. Similarly, the README remains consistent and unchanged; it currently mistakenly suggests that the homebrew_uninstalled_packages is defaulted to [] like the other documented variables.
  • The task usage of homebrew_uninstalled_packages variable would become consistent and semantically the same as the task for installing packages via homebrew_installed_packages. I don't see a good reason why this task needs to be different, but please enlighten me if there's a use case I can't see.

I've submitted PR #67 with my proposed fix.

Thank you for your time.

geerlingguy pushed a commit that referenced this issue Mar 21, 2017
@geerlingguy
Copy link
Owner

Fixed in above PR!

mikesouza added a commit to mikesouza/ansible-role-homebrew that referenced this issue Mar 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants