Ansible - How to capture command output and save as a several variables
<p>I am trying to write some automation using Ansible and I've come across a situation where I need to use multiple parts of a command output in a task later down the playbook.</p>

<p>I have a task that is going to run the command "lspci | grep Ethernet | grep Gigabit"</p>

<p>The output should look something like this (should be 2 lines of output):</p>

<pre><code>"02:00.0 Ethernet controller: Intel Corporation 82575EB Gigabit Network Connection (rev 02)"
"02:00.1 Ethernet controller: Intel Corporation 82575EB Gigabit Network Connection (rev 02)
</code></pre>

<p>Out of this output, I need to extract 4 pieces of information as variables. </p>

<p>var1 - I want the bus of the first line. Should be "02"</p>

<p>var2 - I want the function of the first line. Should be "0"</p>

<p>var3 - I want the bus of the second line. Should be "02" </p>

<p>var4 - I want the function of the second line. Should be "1"</p>

<p>How do I go about extracting the information from the output into these 4 variables? Doesn't necessarily have to be a single play that gets all 4 variables.</p>

<p>Thanks for the help.</p>