Ansible文字档案忙碌错误 [英] Ansible text file busy error
问题描述
我在Windows主机上设置了Vagrant/Ansible.将Ansible设置为可在Ubuntu guest虚拟机上运行,因为Vagrant up
执行一个shell脚本,该脚本将provisioning yml
文件复制到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
Ansible配置过程中的步骤之一是在/var/www
目录中设置Laravel的新副本.拉入Laravel之后,我的脚本然后进行复制,然后编辑文档根目录(/var/www
)中的.env
文件.
但这是问题所在,它失败并显示text file busy
消息.这是在来宾上作为源和目标发生的副本,因此我想与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共享文件夹上使用Ansible复制"模块显然存在一些问题(参见 https://github.com/ansible/ansible/issues/9526# issuecomment-199443969
I have a Vagrant / Ansible set up on my Windows host. Ansible is set up to run on the Ubuntu guest, as Vagrant up
executes a shell script which copies the provisioning yml
files onto the guest and installs Ansible also on the guest.
The script runs the Ansible set up on the guest with the following command:
# 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
One of the steps in the Ansible configuration process is setting up a fresh copy of Laravel in the /var/www
directory. After pulling in Laravel, my script then copies and then edits the .env
file in document root (/var/www
).
But therein is the problem, it fails with text file busy
message. This is a copy that is happening on the guest as source and destination, so I guess nothing to do with VBox. I have a feeling it has to do with the file name being so unusual, but I have not found an answer.
My task.yml
file for Laravel is:
---
- 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 }}
I have also tried using the template method with the same error:
- name: copy .env file
template: src=env.j2 dest={{ conf_file }}
My conf file contains:
conf_file: /var/www/.env
It fails at the copy step as follows:
==> 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.
The .env
source file is in a folder called files
off the Laravel task folder, same as other items I configure which work OK. The file .env
is not found in the www
folder after it fails so it does not copy it.
There have been some issues with using the Ansible "copy" module on Virtualbox shared folders apparently (cf https://github.com/ansible/ansible/issues/9526) - is the /var/www/
directory a shared folder set up by Vagrant?
Maybe try touch
ing the file first to create it, then copying it:
Change:
- name: copy .env file
copy: src=env.j2 dest={{ conf_file }}
into:
- name: create .env file
shell: touch {{ conf_file }}
- name: copy .env file
copy: src=env.j2 dest={{ conf_file }}
EDIT: This file copy error was fixed in the Ansible 1.9.3 release (July 19th 2015) for some users, but is still a problem for people on Windows hosts running Virtualbox (to do with vboxsf sharing) as of 2016-06-14. The GitHub issue is still closed, but people are still commenting and seem to be supplying possible fixes.
The solution linked below appears to work for most people (several upvotes). It suggests adding the Ansible remote_tmp
configuration setting to your local ~/.ansible.cfg
which instructs Ansible to use a temp folder on the target (shared) filesystem:
https://github.com/ansible/ansible/issues/9526#issuecomment-199443969
这篇关于Ansible文字档案忙碌错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!