ansible:有什么样with_fileglobs远程机器上的文件? [英] ansible: Is there something like with_fileglobs for files on remote machine?

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

问题描述

我试图把这些行到我的东西可以把在ansible剧本:

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?

推荐答案

布鲁斯·普的解决方案有效,但它需要一个另外的文件,并得到一个有些凌乱。下面是一个纯粹的ansible解决方案。

Bruce P's solution works, but it requires an addition file and gets a little messy. Below is a pure ansible solution.

的第一个任务抓住在files_to_copy文件名,并将其存储的列表。第二个任务追加每个文件名,为您提供的路径,并创建符号链接。

The first task grabs a list of filenames and stores it in files_to_copy. The second task appends each filename to the path you provide and creates symlinks.

- name: grab file list
  shell: ls /path/to/src
  register: files_to_copy
- name: create symbolic links
  file:
    src: "/path/to/src/{{ item }}"
    dest: "path/to/dest/{{ item }}"
    state: link
  with_items: files_to_copy.stdout_lines

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

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