2017-06-13 110 views
0

我是Ansible的新手,因此对于更高级的用户来说,这个问题可能看起来很愚蠢。Ansible从标准输出获得列

无论如何,我需要得到值为362496LDFree

我知道我可以使用shell modulepipes and awk,但我想知道,如果它使用的是某种“过滤器”的标准输出的是posisble才达到它的Ansible?

这是从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  - 

回答

1

你可以做这个知道的事实,Ansible /神社支持调用本地类型的方法:

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

stdout_lines[3] - 以第四行, .split() - 将其拆分为令牌,[2] - 取第三个令牌。

+0

谢谢,我知道会有一些其他方式来做到这一点。 – MMT