-
Notifications
You must be signed in to change notification settings - Fork 19
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
Proposal: Load included role vars files from defaults folder. #21
Conversation
+1 For me, the problem described by this proposal is one of the biggest obstacles to develop portable, configurable and redistributable roles. |
basically the same as this?
|
@bcoca - Yes... in that case, would |
no, if you want that behavior it needs to be defined in defaults |
@bcoca: I guess the use case is not fully clear to you? I recently posted a question to the mailing list describing the issue: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/ansible-project/jFf1KfoWxBA/d_jm6QskAQAJ At the moment, you have to decide between portability and configurability of a role, you cannot have both. |
After a short walkthrough over the ansible core code, it seems like this is a rather invasive change. Maybe it would be easier to add a parameter that indicates if existing variables should be overwritten. This would also allow lot's of other use cases. Something like:
For this, I could submit a PR in a few days. Anyway, both approaches have some drawbacks: E.g., variables are not recognized in meta/main.yml. Also, if you use --start-at-task, it won't work. Maybe we should start with the less invasive approach first and think of a more complete solution for the portability/configurability contradiction. |
@pfink - I think that could work (the |
I referenced a commit showing the least invasive change to introduce this feature. Usage e.g.:
(similar to the Default for While implementing and testing it, I realized that would just be some lines more to add Anyway, if the What do you think? |
I would introduce a new module called - include_defaults: Debian.yml would load additional defaults from |
I'm thinking this now might resolve most use cases:
|
It won't help, since |
It's about writing reusable roles. If you can't overwrite role variables outside the role, they're not reusable and you have to import and modify them in every project. |
@geerlingguy @pfink I'm thinking |
# Conflicts: # lib/ansible/plugins/action/include_vars.py
include_role now allows a 'defaults_from' parameter, is that sufficient to handle the use cases? |
On the face of it, it looks like it does. I'll test it in our setup whether it has side effects to use include_role instead of the 'normal' role mechanisms. A minor drawback of this approach in my opinion is that if I publish for a role on Github that has different default vars for different operating systems, I have to dictate the users of this role that they can't use the normal/recommended way to call it. They'll always have to call it via include_role with |
@bcoca if I use:
would this task override variables which are set in Also would be great if |
I added PR ansible/ansible#23738 now as I still think it makes it much more flexible if the user can decide whether he wants to overwrite existing variables with |
fyi, this topic is currently also discussed at https://groups.google.com/forum/#!topic/ansible-devel/J22Sbo9p2cI |
Here also some more major drawbacks for the
with |
+100 For me (as a contributor to many roles, incl. complex multi OS supporting roles like https://github.com/hortonworks/ansible-hortonworks), this is the top issue with ansible roles/vars (AFAIK still no satisfactory solution or feature in latest ansible) ! I think there's quite a number of people that would really like a feature as proposed from @geerlingguy or similar (I'm adding links below), but maybe the urge for it is less obvious with the votes & discussions are too spread: Related issues/PRs:
Related discussions:
|
Role-specific default values for variables are now only used if these variables have not been assigned earlier. This requires a workaround using set_fact because Ansible does not provide a include_defaults like function yet and role variables have a high precedence. For discussion and solutions, see: ansible/proposals#21 Required packages are now installed using virtual packages jm1-container-docker via role virtual_pkg. This makes it easier for users to remove ansible-installed packages later.
Following the split of role 'core' we now depend on role base_system. Required packages are now installed with virtual packages via role virtual_pkg. This makes it easier for users to remove ansible-installed packages later. Role-specific default values for variables are now only used if these variables have not been assigned earlier. This requires a workaround using set_fact because Ansible does not provide a include_defaults like function yet and role variables have a high precedence. For discussion and solutions, see: ansible/proposals#21 Removed update-ccache-symlinks.patch because it now has been applied to ccache in Debian Buster.
Following the split of role 'core' we now depend on role base_system. Required packages are now installed with virtual packages via role virtual_pkg. This makes it easier for users to remove ansible-installed packages later. Role-specific default values for variables are now only used if these variables have not been assigned earlier. This requires a workaround using set_fact because Ansible does not provide a include_defaults like function yet and role variables have a high precedence. For discussion and solutions, see: ansible/proposals#21 Added new configuration options uid and shell, see Ansibles user module for details.
…HOME Following the split of role 'core' we now depend on role base_system. Required packages are now installed with virtual packages via role virtual_pkg. This makes it easier for users to remove ansible-installed packages later. Role-specific default values for variables are now only used if these variables have not been assigned earlier. This requires a workaround using set_fact because Ansible does not provide a include_defaults like function yet and role variables have a high precedence. For discussion and solutions, see: ansible/proposals#21 Environment DEVIL_HOME is no longer supported and file /etc/prepare-container.d/home.sh has been removed because both have never been intended for general use.
…HOME Following the split of role 'core' we now depend on role base_system. Required packages are now installed with virtual packages via role virtual_pkg. This makes it easier for users to remove ansible-installed packages later. Role-specific default values for variables are now only used if these variables have not been assigned earlier. This requires a workaround using set_fact because Ansible does not provide a include_defaults like function yet and role variables have a high precedence. For discussion and solutions, see: ansible/proposals#21 Environment DEVIL_HOME is no longer supported and file /etc/prepare-container.d/home.sh has been removed because both have never been intended for general use.
…HOME Following the split of role 'core' we now depend on role base_system. Required packages are now installed with virtual packages via role virtual_pkg. This makes it easier for users to remove ansible-installed packages later. Role-specific default values for variables are now only used if these variables have not been assigned earlier. This requires a workaround using set_fact because Ansible does not provide a include_defaults like function yet and role variables have a high precedence. For discussion and solutions, see: ansible/proposals#21 Environment DEVIL_HOME is no longer supported and file /etc/prepare-container.d/home.sh has been removed because both have never been intended for general use.
…nstall_*.sh Following the split of role 'core' we now depend on role base_system. Required packages are now installed with virtual packages via role virtual_pkg. This makes it easier for users to remove ansible-installed packages later. Role-specific default values for variables are now only used if these variables have not been assigned earlier. This requires a workaround using set_fact because Ansible does not provide a include_defaults like function yet and role variables have a high precedence. For discussion and solutions, see: ansible/proposals#21 Scripts make_install_elemental.sh, make_install_flame.sh and make_install_fmt.sh must be run as root, so that passwordless sudo calls are unnecessary now. Builds are done with user nobody. Added several scientific apt packages as dependencies.
Detection of fact distribution_codename has been moved to the more generic role 'common'. Role-specific default values for variables are now only used if these variables have not been assigned earlier. This requires a workaround using set_fact because Ansible does not provide a include_defaults like function yet and role variables have a high precedence. For discussion and solutions, see: ansible/proposals#21 Required packages are now installed using virtual packages jm1-base-system-stage[01] via role virtual_pkg. This makes it easier for users to remove ansible-installed packages later. Debconf selections are now handled using Ansible's debconf module.
…names Required packages are now installed with virtual packages via role virtual_pkg. This makes it easier for users to remove ansible-installed packages later. Role-specific default values for variables are now only used if these variables have not been assigned earlier. This requires a workaround using set_fact because Ansible does not provide a include_defaults like function yet and role variables have a high precedence. For discussion and solutions, see: ansible/proposals#21 Role virtual_pkg does support regex package names, which Ansible's apt module does not. Thus we reenable regex pattern matches for several qt5 and KDE5/kf5 packages. kdesrc-build's configuration file .kdesrc-buildrc[.j2] now (a) clones version-specific branches instead of the master branch to lower the risk of build failures, (b) does not run tests and (c) uses Ninja instead of Makefiles.
Being highly motivated to get progress on this topic I
The 2 most promising solution approaches IMHO:
Solutions in detail:
(2) enhanced 'default vars' loading
As (for now) I think °1 should solve my issue mostly (unless I oversaw something), I'll ask @pfink if I can help fix the conflicts in his PR (and hopefully then we can have this merged to devel 👍 ) |
we have voted against this several times, latest one is ansible/community#474 so closing this proposal, feel free to resubmit if new arguments in favor appear. |
Yep, neither of above proposals are possible at the moment .. but we got some new ideas for an acceptable work-around (I will test out and show results here tomorrow) |
Currently, include_vars will include variables files from within a role's vars directory automatically. It would be beneficial to multi-platform or more complex roles to also search for include files within the
defaults
directory, so certain variables could be overridden by playbooks using the roles.See PR for details.