<p>Writing an Ansible playbook where we pull projects from GIT repos and thereafter apply all pulled yamls to a Kubernetes cluster.</p>
<p>I see only an example to apply single yaml files to a Kubernetes cluster but not multiple ones at once. e.g.:</p>
<pre><code>- name: Apply metrics-server manifest to the cluster.
  community.kubernetes.k8s:
    state: present
    src: ~/metrics-server.yaml
</code></pre>
<p>Is there any way of applying multiple yaml files? Something like:</p>
<pre><code>- name: Apply Services to the cluster.
  community.kubernetes.k8s:
    state: present
    src: ~/svc-*.yaml
</code></pre>
<p>Or:</p>
<pre><code>- name: Apply Ingresses to the cluster.
  community.kubernetes.k8s:
    state: present
    dir: ~/ing/
</code></pre>
<p>Is there maybe another Ansible K8s module I should be looking at maybe?</p>
<p>Or should we just run kubectl commands directly in Ansible tasks. e.g.:</p>
<pre><code>- name: Apply Ingresses to the cluster.
  command: kubectl apply -f ~/ing/*.yaml
</code></pre>
<p>What is the best way to achieve this using Ansible?</p>

Going Bananas
<p>You can use k8s Ansible module along with 'with_fileglob' recursive pattern. Below code should work for your requirement.</p>
<pre><code>- name: Apply K8s resources
        k8s:
          definition: &quot;{{ lookup('template', '{{ item }}') | from_yaml }}&quot;
        with_fileglob:
          - &quot;~/ing/*.yaml&quot;
</code></pre>
