Ansible文本文件繁忙错误

The*_*apa 5 file-copying ansible ansible-playbook

我在Windows主机上设置了Vagrant/Ansible.Ansible设置为在Ubuntu guest上运行,因为Vagrant up执行shell脚本将provisioning yml文件复制到guest虚拟机并在guest虚拟机上安装Ansible.

该脚本使用以下命令运行在guest虚拟机上设置的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
Run Code Online (Sandbox Code Playgroud)

Ansible配置过程中的一个步骤是在目录中设置Laravel的新副本/var/www.拉入Laravel之后,我的脚本会复制,然后.env在文档root(/var/www)中编辑文件.

但问题就在这里,它失败了text file busy.这是作为来源和目的地在客人身上发生的副本,所以我想与VBox无关.我觉得它与文件名这么不寻常有关,但我还没有找到答案.

task.yml的Laravel文件是:

---
- 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 }}
Run Code Online (Sandbox Code Playgroud)

我也尝试使用模板方法具有相同的错误:

- name: copy .env file
  template: src=env.j2 dest={{ conf_file }}
Run Code Online (Sandbox Code Playgroud)

我的conf文件包含:

conf_file: /var/www/.env
Run Code Online (Sandbox Code Playgroud)

它在复制步骤失败如下:

==> 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.
Run Code Online (Sandbox Code Playgroud)

.env源文件是一个文件夹,名为在files关闭Laravel任务文件夹,相同的其他项目我配置哪些工作确定.该文件.env是不是在发现www后失败,因此不会复制文件夹.

oce*_*ean 10

显然在Virtualbox共享文件夹上使用Ansible"复制"模块存在一些问题(参见https://github.com/ansible/ansible/issues/9526) - /var/www/Vagrant设置的共享文件夹目录是什么?

也许首先尝试touch创建它,然后复制它:

更改:

- name: copy .env file
  copy: src=env.j2 dest={{ conf_file }}
Run Code Online (Sandbox Code Playgroud)

成:

- name: create .env file
  shell: touch {{ conf_file }}
- name: copy .env file
  copy: src=env.j2 dest={{ conf_file }}
Run Code Online (Sandbox Code Playgroud)

编辑:此文件复制错误已在Ansible 1.9.3版本(2015年7月19日)中针对某些用户修复,但对于运行Virtualbox的Windows主机(与vboxsf共享有关)的人员仍然存在问题,截至2016-06-14 .GitHub问题仍然关闭,但人们仍在评论,似乎正在提供可能的修复.

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

https://github.com/ansible/ansible/issues/9526#issuecomment-199443969

  • 这似乎仍然是Ansible 2.1.0中的一个问题.https://github.com/ansible/ansible/issues/9526仍然关闭,但最近的评论表明其他用户仍然遇到这个问题(就像我一样). (2认同)