1
votes

I need to download the ansible tar from http://archive.apache.org/dist/cassandra/2.2.9/ and install it on multiple servers.

Rather than downloading the file on each host I would like to download the file on the playbook host then copy it to each host for install (to save bandwidth).

In my testing I have managed to copy the tar from the host to the servers

- name: Copy Cassandra
  copy: 
    src: "{{item}}" 
    dest: "{{tmp_dir}}"
  with_items:
    - "{{cassandra_tar}}"

However, I have manually put the cassandra tar in the right place before running the playbook.

How do I make ansible check if the file exists in the playbook host and only download the tar if it doesn't exist?

1
Please check the docs for get_url module. Pay attention to force option.Konstantin Suvorov
The same way you would do it on each target host, except that on localhost. I'm not sure where you see an obstacle.techraf
The issue is that the playbook is executes on the target and not the host.opticyclic

1 Answers

1
votes

To download on you host, specify a delegate, something like :

- name: Download Cassandra
  become: no
  get_url:
    url: "http://archive.apache.org/dist/cassandra/{{cassandra_version}}/{{cassandra_tar}}"
    dest: /tmp
  delegate_to: 127.0.0.1

become: no is to account for using become in the main site.yaml and causes ansible to use the playbook user to download the file to the host.