<p>The below value of private_localaddress needs to passed to &quot;range_start&quot; in yaml file. how to do this ?</p>
<p>Here is the script:</p>
<pre><code>#!/bin/bash
MAC=`curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/`
myarr=($MAC)

for val in ${myarr[@]}; do
   interfaceindex=`curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/$val/device-number`
   if [ $interfaceindex == 2 ];
   then
     private_localaddress=`curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/$val/local-ipv4s`
     echo $private_localaddress
   fi
done
</code></pre>
<p>Here is the YAML file :</p>
<pre><code>---
apiVersion: &quot;k8s.cni.cncf.io/v1&quot;

kind: NetworkAttachmentDefinition

metadata:
  name: worker-private-eth2

spec:
  config: '{
    &quot;cniVersion&quot;: &quot;0.3.1&quot;,
    &quot;ipam&quot;: {
      &quot;type&quot;: &quot;whereabouts&quot;,
      &quot;range&quot;: &quot;10.30.11.0/25&quot;,
      &quot;range_start&quot;: $private_localaddress,
      &quot;range_end&quot;: &quot;10.30.11.127&quot;,
      &quot;routes&quot;: [
        { &quot;dst&quot;: &quot;10.93.123.0/24&quot;, &quot;gw&quot;: &quot;10.30.11.1&quot; }
      ],
</code></pre>
<p>Ffffff</p>

ramesh k
<p>Use a proper yaml parser. Here are some examples:</p>
<h5>Using <a href="https://github.com/mikefarah/yq" rel="nofollow noreferrer">mikefarah/yq</a>:</h5>
<pre class="lang-sh prettyprint-override"><code>value=&quot;$private_localaddress&quot; yq \
  '.spec.config |= (fromjson | .ipam.range_start = strenv(value) | tojson)'
</code></pre>
<h5>Using <a href="https://github.com/kislyuk/yq" rel="nofollow noreferrer">kislyuk/yq</a>:</h5>
<pre class="lang-sh prettyprint-override"><code>yq -y --arg value &quot;$private_localaddress&quot; \
  '.spec.config |= (fromjson | .ipam.range_start = $value | tojson)'
</code></pre>
<h5>Using <a href="https://github.com/itchyny/gojq" rel="nofollow noreferrer">itchyny/gojq</a>:</h5>
<pre class="lang-sh prettyprint-override"><code>gojq --arg value &quot;$private_localaddress&quot; --yaml-input --yaml-output \
  '.spec.config |= (fromjson | .ipam.range_start = $value | tojson)'
</code></pre>
