Ansible文本文件忙错误

Ansible文本文件忙错误,ansible,ansible-playbook,file-copying,Ansible,Ansible Playbook,File Copying,我在我的Windows主机上设置了一个流浪者/流浪者。Ansible被设置为在Ubuntu客户机上运行,因为Vagrant up执行一个shell脚本,该脚本将provisioning yml文件复制到客户机上,并在客户机上安装Ansible 脚本使用以下命令在来宾上运行Ansible设置: # Ansible installations sudo apt-get install -y ansible # Copy all Ansible scripts to the ubuntu guest

我在我的Windows主机上设置了一个流浪者/流浪者。Ansible被设置为在Ubuntu客户机上运行,因为
Vagrant up
执行一个shell脚本,该脚本将
provisioning yml
文件复制到客户机上,并在客户机上安装Ansible

脚本使用以下命令在来宾上运行Ansible设置:

# Ansible installations
sudo apt-get install -y ansible

# Copy all Ansible scripts to the ubuntu guest
sudo cp -rf -v /vagrant/provisioning /home/vagrant/

# cp /vagrant/hosts /home/vagrant/
sudo chmod 666 /home/vagrant/provisioning/hosts

# Install roles
sudo ansible-playbook /home/vagrant/provisioning/local.yml -i /home/vagrant/provisioning/hosts --connection=local
Ansible配置过程中的一个步骤是在
/var/www
目录中设置Laravel的新副本。拉入Laravel后,我的脚本将复制并编辑文档根目录中的
.env
文件(
/var/www

但问题就在这里,当
文本文件忙时
消息失败。这是一个发生在作为源和目标的来宾上的拷贝,所以我猜与VBox无关。我有一种感觉,这与文件名如此不同寻常有关,但我还没有找到答案

Laravel的
task.yml
文件是:

---
- name: Clone git repository
  git: >
      dest=/var/www
      repo=https://github.com/laravel/laravel.git
      update=no
  sudo: yes
  sudo_user: www-data
  register: cloned

- name: copy .env file
  copy: src=env.j2 dest={{ conf_file }}

- name: set APP_DOMAIN={{ server_name }}
  lineinfile: dest=/var/www/.env regexp='^APP_DOMAIN=' line=APP_DOMAIN={{ server_name }}
我也尝试过使用模板方法,但出现了相同的错误:

- name: copy .env file
  template: src=env.j2 dest={{ conf_file }}
我的conf文件包含:

conf_file: /var/www/.env
它在复制步骤失败,如下所示:

==> default: TASK: [laravel | copy .env file] **********************************************
==> default: failed: [10.0.1.10] => {"failed": true, "md5sum": "a380715fa81750708f7b9b6fea1a48fe"}
==> default: msg: Could not replace file: /root/.ansible/tmp/ansible-tmp-1441176559.19-197929606462535/source to /var/www/.env: [Errno 26] Text file busy
==> default:
==> default: FATAL: all hosts have already failed -- aborting
==> default:
==> default: PLAY RECAP ********************************************************************
==> default:            to retry, use: --limit @/root/local.retry
==> default:
==> default: 10.0.1.10                  : ok=21   changed=18   unreachable=0    failed=1
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

.env
源文件位于Laravel任务文件夹下名为
files
的文件夹中,与我配置的正常工作的其他项目相同。文件
.env
失败后在
www
文件夹中找不到,因此它不会复制该文件。

在Virtualbox共享文件夹(cf)上使用Ansible“copy”模块时出现了一些问题-
/var/www/
目录是Vagrant设置的共享文件夹吗

可以尝试
触摸
先创建文件,然后复制:

更改:

- name: copy .env file
  copy: src=env.j2 dest={{ conf_file }}
进入:

编辑:对于某些用户,Ansible 1.9.3版本(2015年7月19日)修复了此文件复制错误,但对于运行Virtualbox(与vboxsf共享有关)的Windows主机上的用户来说,这仍然是一个问题。GitHub问题仍然没有解决,但人们仍在发表评论,似乎正在提供可能的解决方案

下面链接的解决方案似乎适用于大多数人(几个人)。它建议将Ansible
remote\u tmp
配置设置添加到本地
~/.Ansible.cfg
,以指示Ansible使用目标(共享)文件系统上的临时文件夹:


使用ansible 2.2,您还可以设置unsafe_writes=yes

Hi@Ocean,谢谢。是的,
/var/www
是共享文件夹,我看到了您提到的bug,但那是从2014年11月开始的。还没修好吗??顺便说一句,其他文件通过这个过程复制OK,但不会复制到
www
文件夹…另外,Ubuntu box上安装了什么Ansible版本?Hi@ocean,Windows 10上所有组件的最新(现在)版本。我正在尝试你的建议,并将向你汇报。谢谢。嗨@Ocean,即使有你的建议,问题依然存在。谢谢。在Ansible 2.1.0中,这似乎仍然是一个问题。仍然关闭,但最近的评论表明,其他用户仍然遇到这个问题(就像我一样)。
- name: create .env file
  shell: touch {{ conf_file }}
- name: copy .env file
  copy: src=env.j2 dest={{ conf_file }}