ansible - Ansible 迭代统计结果并创建目录
问题描述
致命:[172.24.66.221]:失败!=> {“msg”:“条件检查've_exists.stat.exists == False'失败。错误是:评估条件时出错(ve_exists.stat.exists == False):'dict object'没有属性' stat'\n\n错误似乎出现在“/var/lib/awx/projects/_47__tomcat_debug/test.yml”中:第 95 行,第 9 列,但可能\n在文件中的其他位置,具体取决于确切的语法问题。 \n\n违规行似乎是:\n\n\n - name: Create the directory\n ^ here\n"} fatal: [172.24.66.173]: FAILED! => {“msg”:“条件检查've_exists.stat.exists == False'失败。错误是:评估条件时出错(ve_exists.stat.exists == False):'dict object'没有属性'统计'
- name: Run the tasks inside the block
block:
- name: check the directory if already exist
stat:
path: /vtxnfs/{{ item }}
with_items:
- "vera_repository"
register: ve_exists
- name: Create the directory
file:
path: /vtxnfs/{{ item }}
state: directory
owner: "{{ user }}"
group: "{{ user }}"
mode: "0755"
with_items:
- "vera_repository"
when: ve_exists.stat.exists == False
解决方案
试试下面的代码,它将检查目录的存在。
主机:本地主机任务:
名称:Ansible 检查目录。统计:路径:/project/devops/test 寄存器:my_folder
名称:“如果目录已存在则回显”调试:味精:“测试目录已存在”何时:my_folder.stat.exists
名称:“Ansible 创建目录,如果不存在”文件:路径:/project/devops/test 状态:目录模式:0755 组:root 所有者:root 时间:my_folder.stat.exists == false
推荐阅读
- python-3.x - 通过另一列的结果累积减少列中的值
- ag-grid - 使用 AG-Grid 视口模型进行行分组
- swift - 取消对 OperationQueue 的所有操作
- html - 如何获取标签内的单选按钮值?
- ios - 从子视图控制器推送视图控制器
- windows - 如何修复“--go_out:protoc-gen-go:系统找不到指定的文件。” 错误
- python - 有什么方法可以获取第一个元素并计算它在熊猫列中出现的次数?
- java - Java Kafka 消费者和 avro 反序列化器
- python - set_column 未将颜色格式应用于大型 Excel 文件的列
- sql - 每日数据未显示没有数据的日期 - 报告也需要 0 日期