<p>I'm trying to automate the following:</p>
<ol>
<li>Apply the Physical Volumes
<ul>
<li>kubectl apply -f food-pv.yaml</li>
<li>kubectl apply -f bar-pv.yaml</li>
</ul>
</li>
<li>Apply the Physical Volume Claims
<ul>
<li>kubectl apply -f foo.yaml</li>
<li>kubectl apply -f bar.yaml</li>
</ul>
</li>
<li>Apply the Services
<ul>
<li>kubectl apply -f this-service.yaml</li>
<li>kubectl apply -f that-nodeport.yaml</li>
</ul>
</li>
<li>Apply the Deployment
<ul>
<li>kubectl apply -f something.yaml</li>
</ul>
</li>
</ol>
<p>Now I could run the cmds as shell commands, but I don't think that's the proper way to do it. I've been reading thru the Ansible documentation, but I'm not seeing what I need to do for this. Is there a better way to apply these yaml files without using a series of shell cmds?</p>
<p>Thanks in advance</p>

Benjamin W Larson
<p>The best way to do this would be to use <a href="https://github.com/ansible-collections/kubernetes.core" rel="nofollow noreferrer">ansible kubernetes.core collection</a></p>
<p>An example with file:</p>
<pre><code>- name: Create a Deployment by reading the definition from a local file
  kubernetes.core.k8s:
    state: present
    src: /testing/deployment.yml
</code></pre>
<p>So, you could loop from different folders containing the yaml definitions for your objects with <code>state: present</code></p>
