Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible - Unarchive module overwriting

Tags:

ansible

i am working with ansible and using a playbook. In this playbook I am performing a download (from a web url) and unarchive of a file into hosts (using unarchive module), and after that I am copying some files from control machine into hosts (using copy module).

What is happening is that every time I use unarchive module, although every file is the same, ansible is overwriting files in hosts. How can I make it so that it does not overwrite if contents are the same?

My playbook:

---
- hosts: group1
sudo: yes
tasks:

  - name: Download and Extract apache
  unarchive:
   src: http://mirrors.up.pt/pub/apache/tomcat/tomcat-9/v9.0.1/bin/apache-tomcat-9.0.1.tar.gz
   dest: /opt/
   remote_src: yes

- name: Copy file to host
  copy: src=/etc/ansible/files/myfile.xml dest=/opt/apache-tomcat-9.0.1/conf/myfile.xml
like image 240
fr0zt Avatar asked Nov 22 '17 14:11

fr0zt


People also ask

How do you run a command in Ansible?

The command module takes the command name followed by a list of space-delimited arguments. The given command will be executed on all selected nodes. The command(s) will not be processed through the shell, so variables like $HOSTNAME and operations like "*" , "<" , ">" , "|" , ";" and "&" will not work. Use the ansible.


1 Answers

Add a creates option referencing something the unarchive places.

c.f. the documentation page here (check the version against what you are using.)

e.g.:

- unarchive:
    remote_src : yes
    src        : "{{ url }}"
    dest       : "{{ install_dir }}/"
    creates    : "{{ flagFile }}" 

If the unarchive creates a /tmp/foo directory with a file named bar, then flagFile can be /tmp/foo/bar, and unarchive won't run again if it's already there.

like image 110
Paul Hodges Avatar answered Sep 23 '22 14:09

Paul Hodges