【发布时间】:2015-02-17 15:21:29
【问题描述】:
是否有使用 ansible(不是任何其他脚本)格式化 ansible 输出的选项?比如
name: Show version
sudo: true
hosts: web_front_end
tasks:
- name: Create yum cache
shell: yum makecache
- name: Check the version of Portal
shell: rpm -qa | grep portal
register: portal
- debug: msg={{portal.stdout}}
tags:
- portal
- wfe
我只想得到
TASK: [debug msg={{portal.stdout}}]
部分。甚至有没有办法只获取shell命令输出?
【问题讨论】:
-
我现在已经非常了解 Ansible,但从未见过任何可以帮助您的功能。
-
您可以通过管道传输 Ansible 的输出并使用 perl/sed/awk/任何可以执行此操作的 bash 工具对其进行处理……这种方法有问题吗?用这种方式把它弄出来真的很容易。
-
我知道编写一个 python/ruby/perl/sed/awk/whatever 工具来做到这一点没有问题,但我想做一个 Jenkins 工作并避免涉及任何其他脚本
-
我看不出这是 Jenkins 的问题,它可以执行 bash?如果您必须通过
ansible host1 playbook.yml调用 Ansible,您不妨将其输出到 perl:ansible host1 playbook.yml | perl -ne 'do_perl_magic_that_prints_only_what_you_want' -
寻找相同的,我有很大的输出,因为
\r\n部分,我无法真正阅读。
标签: bash output ansible ansible-playbook