ansible - 如何在 Ansible 中使用调试打印语句
问题描述
角色内的文件main.yaml
在下面我想打印一些消息,如“目录创建/存在”。当我使用类似下面的东西时,我得到了错误 -
错误:任务中指定的多个操作:“文件”和“确保该目录存在以下载工件”
---
- name: Ensuring that directory exists to download the artifacts
debug:
msg: "Directory Created/Existed"
file:
path: "{{ local_server_release_location }}"
state: directory
解决方案
不可能在一项任务中同时使用debug
和file
模块。
相反,鉴于目录应存在于 localhost,创建目录并测试其存在。例如
- name: Create directory
file:
path: "{{ local_server_release_location }}"
state: directory
delegate_to: localhost
- name: Ensuring that directory exists to download the artifacts
debug:
msg: "Directory exists"
when: local_server_release_location is directory
推荐阅读
- wordpress - DevTools 无法加载 SourceMap:无法加载内容
- java - RestAssured - 在调用 API B 的主体中使用来自 API A 的响应值
- java - Lombok - 将 @EmbeddedId 字段暴露给 @SuperBuilder
- r - 如何通过自定义函数在 r 中的 for 循环中使用向量
- python - 将保存的模型 (.pb) 转换为 keras 模型 (.h5)
- vba - Word VBA 宏快捷键中的斯堪的纳维亚字母和特殊字符
- c - “解包”宏参数
- matlab - 比较matlab中的2个浮点数
- asp.net - ASP.NET Classic 不使用 WebForm_PostBackOptions 的默认选项创建按钮回发
- python - 在 Pandas 中将字符串类型列转换为数字列