-
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
template
and other modules break zero-assumption declarative configuration principle
#206
Comments
You leave out mode/acls/selinux/etc that are also conditional on the state of the remote system. In most cases we only change what we need to match the information provided in the task itself. When it comes to directory, we know template always outputs a file, this is an issue with the 'copy' action (which template uses) as it assumes that if the destination is a directory, you meant to copy into it, not over it. I"m not sure that changing this inside the action at this point is a good idea, the play/role itself can take care of this with a simple 'stat' to the destination instead. |
I'd argue it requires much more than a simple In current situation the admin is basically required to either write configuration checker logic to double-check the result of all the instances of the affected tasks whenever there is even a remote possibility the system is in an unknown state My proposal doesn't break anything while it allows the module(s) to be much more deterministic. You correctly state that "it assumes that if the destination is a directory, you meant to copy into it" which is imho the worst possible thing a config management tool could ever do - to assume anything, let alone the admins will that is, on top of everything, based on something the admin might not even have control of. |
Ansible is not just CM, it is an automation tool, it allows you to do CM by creating plays/roles that handle these cases. You can also solve this issue by creating a custom template (or copy) action that functions the way you want. |
I'm well aware I can fix issues by creating custom patches, but thanks for the suggestion anyway. I guess I missed the point of these "proposals". Feel free to close this and sorry to have wasted your time. |
@jficz I'm not even talking about custom patches (though those are always possible) but a custom plugin. This is a fundamental part of how Ansible is designed, with the knowledge that we cannot support 100% of the use cases so we allow for simple override and additions via the plugin system. This is not a waste of time, proposals are here to discuss major new features or redesigns, it also gives us a look into what people are thinking and how they are using Ansible, this is useful even when we reject a proposed change. |
Proposal: a consistent behavior for modules like
template
which act differently based on what state thedest
file isAuthor: Jakub Fišer <@jficz> IRC: jficz
Date: 2022-08-09
Motivation
In the declarative config management world one assumes that after an atomic, self-contained step is done, the target system is in the declared state. I'll use the
builtin.temlplate
module as an example which breaks that assumption.Problem
With declarative configuration approach, the resulting state of the target system should always be the same regardless of what state the system was before. The
template
module breaks this principle.The state the target system is in after the
template
module execution is directly dependent on the state the system was before the module was executed. This means that after thetemplate
module is applied, the admin cannot make any definite assumption as to what state the system is in.Specifically, the
template
module result is directly dependent on what thedest
file is. If it is a directory, the result is different from when it is a file or if it doesn't exist at all.If
dest
doesn't exist or is a file,template
module creates/replaces thedest
file content with the content of the template source.If
dest
, however, is a directory, the module assumes that the admin wants to puts the template file(s) inside that directory and does that.There is no known way (at least to me) to control this behavior explicitly. Admin cannot assume either result until they make their own procedural tests (like
stat
, etc) which means that they cannot depend on the module's declarativeness and always have to double-check it's results.The default behavior should not change to not break current workflows but the admin should have the option to make
template
module (and others which behave the same) zero-assumption and declarative. A flag or set of flags should exist which will make the result definite at the time of declaration (as opposed to the time of execution).Example
^^^ In this case
template
should either delete thedest
file if it is a directory or fail audibly ifdest_force: false
.^^^ In this case, similarly to the above, the module should delete
dest
if it is a regular file or fail audibly itdest_force: false
.Testing (optional)
Standard module tests I guess.
Documentation (optional)
Affected module's docs should be updated.
The text was updated successfully, but these errors were encountered: