2016-01-26 21 views
14

In un playbook Ansible voglio eseguire le attività se esiste una directory non.Come posso eseguire un'attività ansibile solo se un file o una directory NON esiste?

- name: Check for java exists in /opt  
    stat: path=/opt/jdk1.8.0_71 
    register: p 
    when: p.stat.isdir is defined and p.stat.isdir 

Ma cosa devo fare per garantire che le seguenti attività vengano eseguite solo se questa dir non esiste?

- name: Extract java if dir not existing 
    command: tar xzf /tmp/jdk1.8.0_71 chdir=/opt 

risposta

12
- name: Extract java if dir not existing 
    command: tar xzf /tmp/jdk1.8.0_71 chdir=/opt 
    when: not p.stat.exists 
26

Questo è ciò che il parametro creates è perfetto per:

- name: Extract java if dir not existing 
    command: tar xzf /tmp/jdk1.8.0_71 
    args: 
     chdir: /opt 
     creates: /opt/jdk1.8.0_71 

Ansible controllerà per vedere se esiste /opt/jdk1.8.0_71 ed eseguire solo il comando se non esiste.

Documentazione: http://docs.ansible.com/ansible/command_module.html

+5

la sintassi è sbagliata: arg: crea: .... è il modo giusto –

+0

E se ho bisogno di esempio. scarica /tmp/jdk1.8.0_71 prima di quel comando e vuoi che questa attività dipenda anche dal fatto che /opt/jdk1.8.0_71 esista? – Debilski

Problemi correlati