cowsay和ansible
简介
cowsay是一款有趣的ascii图案输出工具,通过它可以方便的输出一头说话的牛牛(马?):
# cowsay hello frankming
_________________
< hello frankming >
-----------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
# cowsay work, work. ready to work.
____________________________
< work, work. ready to work. >
----------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
用法
简约而不简单,这款工具的可配置性相当高,cowsay不光有牛,通过cowsay -l
命令能查到所有可选的动物,随后通过-f
参数指定想要的动物,比如说不想要牛了,换成羊:
# cowsay -f sheep ready to work.
________________
< ready to work. >
----------------
\
\
__
UooU\.'@@@@@@`.
\__/(@@@@@@@@@@)
(@@@@@@@@)
`YY~~~~YY'
|| ||
-e eye_string
和-T tongue_string
能够指定牛的眼睛和嘴巴,不过限制前两个字符生效:
# cowsay -e xx -T 'L|' ready to work.
________________
< ready to work. >
----------------
\ ^__^
\ (xx)\_______
(__)\ )\/\
L| ||----w |
|| ||
-bdgpstwy
则是一系列眼睛/嘴巴的预设定值,使牛变成borg(赛博牛)、dead(死牛)、greedy(贪婪牛)、paranoia(妄想牛)、stoned(石化牛)、tired(累牛)、wired(精神牛)、youthful(年轻牛)。例如死牛:
# cowsay -d work to die.
______________
< work to die. >
--------------
\ ^__^
\ (xx)\_______
(__)\ )\/\
U ||----w |
|| ||
-W column
则是设置一行所能包含字符数的最大值,默认为40个字符,如果超过设定值就会换行:
# cowsay -W 6 ready to work.
_______
/ ready \
| to |
\ work. /
-------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
最后,-n
参数表示不转义换行符等特殊字符,注意该参数后面禁止追加任何其他参数,只能使用标准输入模式输入“话语”,最后使用Ctrl^d表示结束:
# cowsay -n
ready
to
work.
# 输入Ctrl^d
_______
/ ready \
| to |
\ work. /
-------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
和ansible结合
比较神奇的是,cowsay工具能够和ansible无缝衔接,在安装cowsay后,不修改任何东西,ansible中每个task的输出都变成牛说的话:
# ansible-playbook -i inventory/hosts.ini playbooks/setup.yml
< TASK [pre_deploy : set fact myIp] >
-----------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
ok: [localhost]
_________________________________________
< TASK [pre_deploy : set fact masterNode] >
-----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
ok: [localhost]
___________________________________
< TASK [pre_deploy : debug servers] >
-----------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
查一查ansible配置,发现有几个配置是关于cowsay的,可谓是官方钦定了:
# cowsay模板白名单,设为空表示启用所有所有cowsay模板
ANSIBLE_COW_ACCEPTLIST=[]
# cowsay程序路径
ANSIBLE_COW_PATH=
# cowsay模板,默认为default牛,random表示随机,或指定一个模板
ANSIBLE_COW_SELECTION=
# 是否禁用cowsay,默认为false
ANSIBLE_NOCOWS=
值得一提的是ANSIBLE_NOCOWS
配置项,ansible官方的说明如下,其中的why和i_am_no_fun,意思是禁用cowsay的都是无趣的人,令人莞尔一笑。
# ansible-config list|less
ANSIBLE_NOCOWS:
default: false
description: If you have cowsay installed but want to avoid the 'cows' (why????),
use this.
env:
- name: ANSIBLE_NOCOWS
ini:
- key: nocows
section: defaults
name: Suppress cowsay output
type: boolean
yaml:
key: display.i_am_no_fun
最后,看看这个似曾相识的界面。
参考文档
cowsay(1): configurable speaking/thinking cow - Linux man page (die.net)
本文来自博客园,作者:frankming,转载请注明原文链接:https://www.cnblogs.com/frankming/p/15883981.html