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*
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.
Is there any way to do this, or should I just use a shell script?
The copy module copies a file from the local or remote machine to a location on the remote machine. Use the fetch module to copy files from remote locations to the local box. If you need variable interpolation in copied files, use the template module. For Windows targets, use the win_copy module instead.
To copy a file from remote to local in ansible we use ansible fetch module. Fetch module is used to fetch the files from remote to local machine. In the following example i will show you how to copy a file from remote to local using ansible fetch module. Note: If you execute above playbook the target.
You can use the copy module in your Ansible playbook. This module can copy one or more files to the remote system. But you need to use the item keyword in your playbook for multiple files as shown below.
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 }}"
Bruce P's solution works, but it requires an addition file and gets a little messy. Below is a pure ansible solution.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With