2

Ansible 1.9.2 / newer.

Playbook:

# Push Performance tests artifact zip file on remote jmeter machine
- name: Push Performance tests artifact zip file on remote jmeter machine
  copy: src="performance-tests-*.zip"  dest={{ common_download_dir }} 

It errors out:

19:32:08 TASK: [perf_tests | Push Performance tests artifact zip file on remote jmeter machine] *** 
19:32:08 fatal: [jmeter01.server.in.vcloud] => input file not found at /home/service/workspace/run-project-performance-tests/build/artifacts/roles/perf_tests/files/performance-tests-*.zip or /home/service/workspace/run-project-performance-tests/build/artifacts/performance-tests-*.zip
19:32:08 
19:32:08 FATAL: all hosts have already failed -- aborting

I checked on the source machine (where I'm running ansible), the workspace have valid file: performance-tests-0.0.8-20151001.232123-11.zip

Doesn't ansible support shell expansion i.e. * in src= parameter (into all files) during it's copying operation like copy: src="somePath/*.zip" dest="somePathOnRemoteMachine"?

All of the examples on Ansible site: https://docs.ansible.com/ansible/copy_module.html shows.. only one file for src=... parameter.

PS: I'm not using the validate paramter in copy module.

2 Answers 2

3

You can use http://docs.ansible.com/ansible/playbooks_loops.html#looping-over-fileglobs with_fileglob matches all files in a single directory, non-recursively, that match a pattern. It can be used like this::

# copy each file over that matches the given pattern
- copy: src={{ item }} dest=/etc/fooapp/ owner=root mode=600
  with_fileglob:
    - /playbooks/files/fooapp/*
4
  • Sounds promising, I'll try that and update back. Thanks.
    – AKS
    Oct 2, 2015 at 15:38
  • It worked (I used xxxx-.zip) for me. I saw a blog which said if it's just * then it might not work but *. worked.
    – AKS
    Oct 2, 2015 at 16:52
  • HOW would I do the same (shell expansion) if I'm using "unarchive" instead of "copy" module?
    – AKS
    Oct 2, 2015 at 20:38
  • You can use with_fileglob with any module.
    – Dan
    Oct 3, 2015 at 17:25
1

It does not.

I guess the easiest way would be to use the shell module, and issue the cp command directly.

3
  • I expected that. It's really strange that why Ansible can't expand shell (seems like due to Jinja2 ?). Other thing I noticed it doesn't let me use a variable for ex: {{ var_{{ giga }}_value }} .. where giga can be "new" or "old" and var_new_value is "NEW" and var_old_value is "OLD", then using {{ var_{{ giga }}_value }} I can't evaluate it to either of those 2 new_xxx_value variable depending upon what's set in variable giga.
    – AKS
    Oct 2, 2015 at 15:37
  • @ArunSangal It being unable to expand the shell has nothing to do with jinja2. It's because it's not using the shell to evaluate the arguments.
    – Dan
    Oct 3, 2015 at 17:26
  • @ArunSangal Also, it's a bit roundabout, but you can access variables "programmatically" to accomplish what you are looking for in the example in your comment: docs.ansible.com/ansible/…
    – Dan
    Oct 3, 2015 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.