ansible - Ansible:使用 if else 条件在调试消息中打印循环“项目”
问题描述
我正在尝试编写多个服务的停止和启动的摘要。我的代码看起来像
vars:
profiles:
- service01
- service02
- name: Service STOP
command: command to stop a service
with_items: "{{profiles}}"
register: stop
- debug: "var= stop.results.{{item}}.stdout"
with_sequence: "0-{{profiles|length - 1}}"
- name: Service START
shell: Command to start a service
with_items: "{{profiles}}"
register: start
- debug: "var=start.results.{{item}}.stdout"
with_sequence: "0-{{profiles|length - 1}}"
- name: Summary of the WebServer valdiation
debug:
msg: |
"{{'WebServer Stop: Success' if stop.results.['item'].rc == 0 else stop.results.['item'].stderr}}"
"{{'WebServer Start: Success' if start.results.['item'].rc == 0 else start.results.['item'].stderr}}"
with_sequence: "0-{{profiles|length - 1}}"
我无法弄清楚如何打印最后一个任务(WebServer valdiation 的摘要)。它必须遍历项目。有人可以帮我如何打印如下所示的输出。
WebServer Stop: Success
WebServer Start: Success
解决方案
推荐阅读
- python - 根据时间戳对列的值求和
- javascript - 根据名称或ID过滤类型文件的输入
- php - 如何使用第三个作曲家供应商库将关联数组的 PHP 数组转换为 CSV 字符串?
- python - AttributeError 的起源:对象没有属性“cos”
- asp.net-mvc - 删除操作不会激活/触发 ASP.NET Core MVC
- java - iframe 中的复选框 - 如何检查是否有复选框,如果是,请单击它
- html - 为什么我的引导下拉元素渲染不好?
- sql - SQL 中括号的规则。似乎没有工作
- java - Reactor rabbitmq AlreadyClosedException
- javascript - 循环遍历对象数组,并将它们转换为 UL 中的 LI 项