Ansible local_action: stat não encontra meu arquivo

4

Eu quero copiar um arquivo para nós remotos, mas apenas se o arquivo existir. Eu copiei para /tmp/webapps/partner.war

Minha tarefa é:

- local_action: stat path="/tmp/webapps/{{ application }}.war"
  register: war

- name: Copy warfile
  copy: src=/tmp/webapps/{{ application }}.war dest=/tmp/deploy/{{ stage }}/{{ application }}.war
  when: war.stat.exists == true

Mas stat sempre me diz, o arquivo não existe. Se eu executar stat manualmente, ele me mostra que o arquivo está lá.

O resultado:

    TASK: [deploy | stat path="/tmp/webapps/{{ application }}.war"] *************** 
<127.0.0.1> REMOTE_MODULE stat path="/tmp/webapps/partner.war"
<127.0.0.1> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1433920640.68-144173277081367 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1433920640.68-144173277081367 && echo $HOME/.ansible/tmp/ansible-tmp-1433920640.68-144173277081367']
<127.0.0.1> PUT /tmp/tmpzrV_Ne TO /var/lib/awx/.ansible/tmp/ansible-tmp-1433920640.68-144173277081367/stat
<127.0.0.1> EXEC ['/bin/sh', '-c', u'LANG=C LC_CTYPE=C /usr/bin/python /var/lib/awx/.ansible/tmp/ansible-tmp-1433920640.68-144173277081367/stat; rm -rf /var/lib/awx/.ansible/tmp/ansible-tmp-1433920640.68-144173277081367/ >/dev/null 2>&1']
ok: [example.com -> 127.0.0.1] => {"changed": false, "stat": {"exists": false}}

O que eu fiz de errado? : /

    
por Alexander Huck 10.06.2015 / 09:35

2 respostas

3

Torre Ansible usa PRoot que fornece uma interface legal para criar chroot e cadeias semelhantes. Na Docs da torre eles afirmam:

3.5. Playbooks missing access to necessary data due to PRoot issues

When running a playbook that reads and writes information in certain prohibited directories, users may encounter issues with PRoot. PRoot runs the ansible-playbook command within a chroot jail. In cases like these, the running playbook cannot see other playbooks or sensitive data on disk and should the playbook expect to have access to that information, problems will occur. To fine tune your usage of PRoot, there are certain variables that can be set:

# Enable proot support for running jobs (playbook runs only).
AWX_PROOT_ENABLED = False

# Command/path to proot.
AWX_PROOT_CMD = 'proot'

# Additional paths to hide from jobs using proot.
AWX_PROOT_HIDE_PATHS = []

# Additional paths to show for jobs using proot.
AWX_PROOT_SHOW_PATHS = []
    
por 26.09.2015 / 16:55
1

FWIW, tive problemas semelhantes ao tentar encontrar arquivos dentro do diretório 'files' da função (sem Tower envolvido). Eu normalmente referenciá-los como "../files/something", mas isso não funciona para um stat local_action. Em vez disso, isso funciona:

- name: check for optional config file
  local_action: stat path={{ role_path }}/files/{{ inventory_hostname }}/some_file
  register: optional_file

(então eu acho que a moral da história é: use um caminho completo para o arquivo local)

    
por 04.10.2016 / 13:35