ansible:远程机器上的文件是否有类似 with_fileglobs 的东西? [英] ansible: Is there something like with_fileglobs for files on remote machine?

查看:20
本文介绍了ansible:远程机器上的文件是否有类似 with_fileglobs 的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试改变这些 把我可以放在 ansible playbook 的东西写进去:

I'm trying to turn these lines into something I can put in an ansible playbook:

# Install Prezto files
shopt -s extglob
shopt -s nullglob
files=( "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/!(README.md) )
for rcfile in "${files[@]}"; do
    [[ -f $rcfile ]] && ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile##*/}"
done

到目前为止,我有以下几点:

So far I've got the following:

- name: Link Prezto files
  file: src={{ item }} dest=~ state=link
  with_fileglob:
    - ~/.zprezto/runcoms/z*

我知道它不一样,但它会选择相同的文件:除了 with_fileglob 在主机上查找,我希望它在远程机器上查找.

I know it isn't the same, but it would select the same files: except with_fileglob looks on the host machine, and I want it to look on the remote machine.

有什么办法可以做到这一点,还是我应该只使用 shell 脚本?

Is there any way to do this, or should I just use a shell script?

推荐答案

一种清除与 glob 匹配的不需要的文件的干净 Ansible 方法是:

A clean Ansible way of purging unwanted files matching a glob is:

- name: List all tmp files
  find:
    paths: /tmp/foo
    patterns: "*.tmp"
  register: tmp_glob

- name: Cleanup tmp files
  file:
    path: "{{ item.path }}"
    state: absent
  with_items:
    - "{{ tmp_glob.files }}"

这篇关于ansible:远程机器上的文件是否有类似 with_fileglobs 的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆