gpt4 book ai didi

ansible - 检查其中一个文件是否存在于ansible中

转载 作者:行者123 更新时间:2023-12-05 06:14:26 27 4
gpt4 key购买 nike

我正在尝试检查其中一个文件是否存在于 ansible 中。

检查单个文件的代码,完美运行。

- hosts: all
tasks:
- name: Ansible check file exists example.
stat:
path: /Users/data/info.text
register: file_details

- debug:
msg: "The file exists"
when: file_details.stat.exists

但我想检查/Users/data/info.text 或/Users/data/info.html 是否存在,这里我尝试使用或运算符,但它是说无效的 yml 文件。

- hosts: all
tasks:
- name: Ansible check file exists example.
stat:
path: /Users/data/info.text or /Users/data/info.html
register: file_details

- debug:
msg: "The file exists"
when: file_details.stat.exists

最佳答案

试试这个

    - stat:
path: "{{ item }}"
register: file_details
loop:
- info.text
- info.html

- debug:
msg: The files exist
when: file_details.results|map(attribute='stat.exists') is all

关于ansible - 检查其中一个文件是否存在于ansible中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62888703/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com