基于任务结果的Ansible消息输出

编程入门 行业动态 更新时间:2024-10-25 09:23:47
本文介绍了基于任务结果的Ansible消息输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Ansible是否可以根据任务结果显示不同的消息?

Is it possible in Ansible to display different messages based on a result of the task?

例如

- name: check_prometheus_status_kafka shell: /usr/sbin/ss -lnt|awk '{ print $4}'|grep 9071 |sed 's/\*//'| sed 's/\://' register: prom_status tags: - check_prometheus_status_kafka - name: post_message_prom_kafka debug: msg="Prometheus for Kafka listening in {{ prom_status.stdout }}" when: prom_status.stdout == "9071" tags: - post_message_prom_kafka

我想要的是一条额外的消息,它会输出类似 Kafka的Prometheus不在端口{{prom_status.stdout}}

What I want is an additional message which would output something like Prometheus for Kafka is NOT listening on port {{ prom_status.stdout }}

推荐答案

您的问题不是很清楚,但这是您需要考虑的问题(使用 actual_port 的值):

Your question is not very clear, but here is something for your consideration (play with the value of actual_port):

--- - hosts: localhost vars: port_to_listen_on: "9071" actual_port: "9071" tasks: - debug: msg: "Prometheus for Kafka {{ (actual_port == port_to_listen_on) | ternary ('', 'NOT ') }}listening in {{ port_to_listen_on }}" # or - debug: msg: "Prometheus for Kafka {{ 'NOT ' if (actual_port != port_to_listen_on) else '' }}listening in {{ port_to_listen_on }}"

更多推荐

基于任务结果的Ansible消息输出

本文发布于:2023-11-15 00:37:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1589572.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:消息   Ansible

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!