比较ansible中的坐骑

比较ansible中的坐骑,ansible,Ansible,我在ansible中要求比较维护前后的装载数量,为此我使用以下任务。我们需要比较预计数和后计数,如果值有差异,它应该抛出一条消息来检查主机。请告知 -name:进行预计数 shell:df-h | awk'NR>1{print$1}| grep-v“tmpfs”| wc-l 寄存器:预计数 -姓名:进行邮政统计 shell:df-h | awk'NR>1{print$1}| grep-v“tmpfs”| wc-l 注册:邮戳 尝试以下操作: -name:进行预计数 shell:df-h | aw

我在ansible中要求比较维护前后的装载数量,为此我使用以下任务。我们需要比较预计数和后计数,如果值有差异,它应该抛出一条消息来检查主机。请告知

-name:进行预计数
shell:df-h | awk'NR>1{print$1}| grep-v“tmpfs”| wc-l
寄存器:预计数
-姓名:进行邮政统计
shell:df-h | awk'NR>1{print$1}| grep-v“tmpfs”| wc-l
注册:邮戳
尝试以下操作:

-name:进行预计数
shell:df-h | awk'NR>1{print$1}| grep-v“tmpfs”| wc-l
寄存器:预计数
-姓名:进行邮政统计
shell:df-h | awk'NR>1{print$1}| grep-v“tmpfs”| wc-l
注册:邮戳
-调试:
msg:'装载计数有差异,请检查'
时间:预计数.stdout_行[0]| int!=邮戳。标准线[0]|整数

我想您正在寻找模块。您可以使用此选项打印消息,也可以根据条件失败

例如:

-name:进行预计数
shell:df-h | awk'NR>1{print$1}| grep-v“tmpfs”| wc-l
寄存器:预计数
-姓名:进行邮政统计
shell:df-h | awk'NR>1{print$1}| grep-v“tmpfs”| wc-l
注册:邮戳
-断言:
即:
-前计数==后计数
fail_msg:{{{Premounts}}和postmounts:{{{postmounts}}不匹配
成功消息:“坐骑匹配。”
您可以使用Ansible fact
Ansible_mounts
来获取此计数,而不是运行
df
命令并获取装载数

例如:

-设置事实:
预计数:{{ansible_mounts}
#中间的一些任务
#再次收集事实
-设置:
-设定事实:
邮戳:{{ansible_mounts}
-断言:
即:
-前计数==后计数
fail_msg:{{{Premounts}}和postmounts:{{{postmounts}}不匹配
成功消息:“坐骑匹配。”

非常感谢Seshadri,让我回去检查一下……嗨,Seshadri,当我使用df而不是ansible_挂载时,我收到了错误。它给出了以下错误致命:[hostname]:失败!=>{“断言”:“premounts==postmounts”,“changed”:false,“evaluated_to”:false,“msg”:“premounts&postmount不匹配”}嗨,seshadri_c,你如何写出答案来显示颜色?有简单的方法吗?嗨@garylopez我正在使用语法突出显示功能。我将代码块显式设置为:``yml`。您不必要地使用了太多的命令。只需将df管道发送到awk-df-h | awk'/tmpfs/{cnt++}END{print cnt}'Hi Gary,感谢您回复我,但是当我测试这个时,我得到的消息是msg:[2]。不确定大括号中的数字是什么意思。我修改了答案,如果两个装载计数之间存在差异,ansible将显示消息“装载计数存在差异,请检查”。