Ansible 文本文件繁忙错误

标签 ansible ansible-playbook file-copying

我在我的 Windows 主机上设置了 Vagrant/Ansible。 Ansible 设置为在 Ubuntu 客户机上运行,​​如 Vagrant up执行一个复制 provisioning yml 的 shell 脚本文件到客户机上并在客户机上安装 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) 中的文件。

但这就是问题所在,它失败了 text file busy信息。这是作为源和目标在 guest 上发生的副本,所以我想与 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 }}

我也尝试过使用同样错误的模板方法:
- 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源文件位于名为 files 的文件夹中关闭 Laravel 任务文件夹,与我配置的其他项目相同,它们可以正常工作。文件.env未在 www 中找到失败后的文件夹,因此它不会复制它。

最佳答案

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

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

改变:

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

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

编辑:此文件复制错误已在 Ansible 1.9.3 版本(2015 年 7 月 19 日)中为某些用户修复,但对于 上的人来说仍然是一个问题。 window 正在运行的主机 虚拟机 (与 vboxsf 共享有关)截至 2016 年 6 月 14 日。 GitHub 问题仍然关闭,但人们仍在发表评论,似乎正在提供可能的修复。

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

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

关于Ansible 文本文件繁忙错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32346342/

相关文章:

C++ 将文件从 Qt 传输到外部 USB 驱动器

powershell - 通过 power-shell 并行复制多个文件而不使用任何第三方软件?

ssh - Ansible ad-hoc 命令有效,但运行 playbook 无法使用 ssh 进行身份验证

ansible - 使用模块而不是 shell 与 Ansible 临时挂载 smb 共享

ansible 1.6 > 在 with_items 循环中使用 with_first_found?

ansible - 如何在 Ansible 中打破 `with_lines` 循环?

python - Roots > Trellis > Ansible 2.4 > 错误!意外异常,这可能是错误 : No module named six

ansible - 为 Ansible playbook 中的一组任务设置 remote_user,而无需为每个任务重复设置

Ansible:ansible_domain 或 facter_domain - 如何获取 list 文件中提到的主机名的域值

cocoa - 将文件复制到应用程序支持或从应用程序支持复制文件