-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
k8s module: Add parameter to invoke the template
module when given a path to k8s yaml files
#60134
Comments
Files identified in the description: If these files are inaccurate, please update the |
I'm on board with this. I have basically had to add that boilerplate about 7 jillion times, and it would be nice to just have built-in functionality that would allow me to pass a .j2 file with multiple documents that's parsed into the individual docs without writing out an explicit lookup... |
I also agree. Forcing a lookup template etc is unnecessary repetitive and annoying to keep doing especially given how common reading in a templatized YAML file will be. |
big +1 from me, would make k8s targeted playbooks/roles much much cleaner |
Lovely idea, not at all convinced that it's workable in practice. How will the module get all the required variables to do the templating? Write the logic once using e.g. kube-resource role and then move on with your lives. We literally have one kubernetes role that manages every kubernetes resource. https://github.com/willthames/ansible-role-kube-resource/blob/master/tasks/main.yml
|
One other problem with this idea is that templating is done on the controller but the I'd suggest this would be better as a proposal - it's not a |
@willthames At a cursory glance, this is marvelous. Will let the others look and dig in while I do the same this morning. But, regardless, thank you. cc @geerlingguy @tima @fabianvf |
I'm looking through what it would take to make this possible in the
I see the potential issues @willthames raises. I also know that those of us using this functionality in practice kind of wrap things up in roles to mask over the clunky inability to easily template, as roles like kube-resource and But Jinja templating is probably the main reason I ever considered using Ansible for K8s resource management, and I think having this be available through the core At the very least, I wouldn't have to explain lookup plugins and Jinja filters just to demonstrate one simple templated K8s resource definition being applied to a K8s cluster through Ansible. I the end, I find it much more comprehensible to write: - name: Create Mcrouter resources.
k8s:
template: mcrouter.yaml.j2 instead of: - name: Create Mcrouter resources.
k8s:
definition: "{{ lookup('template', 'mcrouter.yaml.j2') | from_yaml }}" |
I have kind of a PoC in a branch of my k8s collection (see https://github.com/geerlingguy/ansible-collection-k8s/issues/2#issuecomment-520597539)—but I do see how on the module level, it may be impossible to get the templating done when run on a destination machine. (in response to "How will the module get all the required variables to do the templating?") However, if using It's definitely not as simple as "plug Templar into k8s module", but I still think if it's possible to have templating built in, it would be a huge UX/discovery improvement. |
I'd just like to note that there are also some very hard lessons (the kind that come out of Post Incident Reviews) now encoded in ansible-role-kube-resource that would be more difficult to embed in k8s_template. This assumes you ever manage a bunch of resources in a single template (an incredibly common pattern) Basically there's a reason I loop across an (the issue is that if we're updating a service because of a change in a deployment's pod's port or labels, that service might not have any targets if the pod changes fail but we carry on and update the service anyway) |
Thinking about this some more, with decent error handling and the loop inside k8s_template, we could be safer from the problem I identify above. One thing I find hard with the "run one huge manifest in a single task" approach is the lack of error reporting - ok, so my manifest failed because of applying a single resource, but which one? With a looped include_task approach I can name the task appropriately (usually "Applying {{ resource.metadata.name }} {{ resource.kind }}" or similar) and it's obvious. |
I've moved this feature request into the Kubernetes collection repository: https://github.com/ansible-collections/kubernetes/issues/37 This request should be closed and further discussion moved to that thread. |
Files identified in the description: If these files are inaccurate, please update the |
Files identified in the description: If these files are incorrect, please update the |
Thank you very much for your interest in Ansible. This plugin/module is no longer maintained in this repository and has been migrated to https://github.com/ansible-collections/community.kubernetes Migrated this issue in the above repository - https://github.com/ansible-collections/community.kubernetes/issues/176. If you have further questions please stop by IRC or the mailing list:
|
SUMMARY
k8s module: Add parameter to invoke the
template
module when given a path to k8s yaml filesISSUE TYPE
COMPONENT NAME
k8s module template processor
ADDITIONAL INFORMATION
I think it'd be beneficial for the k8s module (and subsequently operator-sdk) to avoid using Jinja2 templating when possible. In a nutshell, I'd like a cleaner, simpler way to invoke templating of k8s YAML files as their deployed via Ansible. Example of the current state: https://github.com/geerlingguy/mcrouter-operator/blob/a3babecae85ece431f5cf316bd8a407ba60a5b42/roles/mcrouter/tasks/main.yml
It's 431 bytes in total, I get that. It's not a lot of Jinja2, I get that too. Jinja2 is another thing to add on to the pile of things to learn before you can harness it and removing that barrier will be beneficial. The effort of learning Jinja2 for this use case (globally) far outstrips our effort to help solve this problem on behalf of our users.
The overarching goal is to minimize the amount of Jinja2 needed in playbooks to make this work.
The text was updated successfully, but these errors were encountered: