MMT
MMT

Reputation: 2111

Ansible get column from stdout

I'm new to Ansible an thus this question may seem silly to more advanced users.

Anyway, I need to get the value 362496 for the column LDFree.

I know I can use the shell module with pipes and awk, but I was wondering if it's posisble to achive it in Ansible using some sort of "filter" for STDOUT?

This is the STDOUT from the CLI:

       -------------------------(MB)-------------------------                      
   CPG ---EstFree---- -------Usr------- ---Snp---- ---Adm---- -Capacity Efficiency-
  Name RawFree LDFree    Total     Used Total Used Total Used   Compaction    Dedup
SSD_r6  483328 362496 12693504 12666880 12288 2048  8192 1024          1.0        -

Upvotes: 0

Views: 3685

Answers (1)

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68269

You can done this knowing the fact that Ansible/Jinja support calling methods of native types:

- command: cat test.txt
  register: cmd_res
- debug:
    msg: "{{ cmd_res.stdout_lines[3].split()[2] }}"

stdout_lines[3] – take forth line, .split() – split it into tokens, [2] – take third token.

Upvotes: 3

Related Questions