大网数据广告活动
服务器运维问答

Ansible local_action: stat doesnt find my file

· 52CE 我爱测

I want to copy a file to remote nodes, but only if the file exists. I copied it into /tmp/webapps/partner.war My Task is: - local_action: stat path="/tmp/webapps/{{ application }}.war" register: war - name: Copy warfile copy: src…

问题原文

原帖链接 · Alexander Huck · CC BY-SA 3.0

I want to copy a file to remote nodes, but only if the file exists. I copied it into /tmp/webapps/partner.war

My Task is:

- 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

But stat always tells me, the file does not exist. If I run stat manually, it shows me the file is there.

The result:

    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}}

What did I do wrong? :/

已采纳解答

原帖链接 · chicks · CC BY-SA 3.0

Ansible Tower uses PRoot which provides a cool interface for creating chroot and similar jails. In the Tower docs they state:

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 = []

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-06-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。