首页 > 解决方案 > 如何在 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

标签: ansibleansible-inventory

解决方案


不可能在一项任务中同时使用debugfile模块。

相反,鉴于目录应存在于 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


推荐阅读