在 chown 上使用 Ansible 配置 Ubuntu 16.04 Vagrant 失败 [英] Provisioning Ubuntu 16.04 Vagrant with Ansible fails on chown
问题描述
我正在尝试使用 Ansible 配置 Ubuntu Xenial Vagrant 来宾.它在 Ubuntu 14.04 上正常工作,但在 16.04 上失败.我得到的错误是
chown failed: 查找用户 vagrant 失败
我正在运行的任务如下:
- 名称:确保/srv/web 存在变成:是文件:路径:/srv/web状态:目录模式:0755所有者:{{ remote_user }}"
搜索没有找到太多帮助.
谢谢!
对 Digital Ocean 14.04 液滴的进一步测试也显示了这个问题.
编辑 2:
"msg": "chown failed: failed to look up user vagrant"
这是错误跟踪,可帮助您找到确切的错误.此错误的解决方案 1:
下载一些其他的vagrant box,我推荐这个vagrant box geerlingguy/ubuntu1604
口碑很好
此错误的解决方案 2:
使用官方的 vagrant box,你可以像我一样做来减轻这个错误.将以下内容添加到您的 Vagrantfile
:
config.vm.provision "shell" 做 |s|ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.stripssh_user = ENV['用户']s.inline = <<-SHELLadduser --disabled-password --gecos "" #{ssh_user}mkdir -p/home/#{ssh_user}/.ssh触摸/home/#{ssh_user}/.ssh/authorized_keyschown -R #{ssh_user}./home/#{ssh_user}/.sshecho "#{ssh_user} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/99-#{ssh_user}echo #{ssh_pub_key} >>/home/#{ssh_user}/.ssh/authorized_keyschmod 0440/etc/sudoers.d/99-#{ssh_user}贝壳结尾
它会做的是,只需为来宾创建您的主机登录用户并为其上传 rsa 密钥.因此,您可以将 playbook 运行到 vagrant 机器上,就好像它是远程机器一样.如果您将进一步遇到任何问题,请告诉我.
希望对您有所帮助.
I am trying to provision an Ubuntu Xenial Vagrant guest with Ansible. It worked correctly on Ubuntu 14.04, but fails on 16.04. The error that I get is
chown failed: failed to look up user vagrant
The task that I am running is the following:
- name: Ensure /srv/web exists
become: yes
file:
path: /srv/web
state: directory
mode: 0755
owner: "{{ remote_user }}"
Searching hasn't found much help.
Thanks!
Edit: Further testing on a Digital Ocean 14.04 droplet also shows this issue.
Edit 2: Full output log at -vvvv level
SOLOUTION#1
Ubuntu 16.04 has python3, not 2.7.x. and Ansible doesn't support for Python 3 yet.
For Ubuntu 16.04 I use the following play to get Python 2.7 installed.
---
- hosts: xenials
gather_facts: no
become: yes
tasks:
- name: Install python 2.7
raw: apt-get update -qq && apt-get install -qq python2.7
- name: check if softlink exists
stat:
path: /usr/bin/python
register: python_file
- name: create softlink for python 2.7
raw: ln -s /usr/bin/python2.7 /usr/bin/python
when: python_file.stat.islnk is not defined
- name: Ensure /srv/web exists
file:
path: /srv/web
state: directory
mode: 0755
owner: "{{ remote_user }}" # hope you have defined this variable in your ansible.cfg
key line is gather_facts: no
which prevents Ansible to execute code on the remote server that the remote server cannot yet support.Without this line,play would fail.
That provides an /usr/bin/python2.7
, which I explicitly point to in my inventory file.
[xenials]
192.168.33.100
[xenials:vars]
ansible_python_interpreter=/usr/bin/python2.7
Note that there is nothing special about the name xenials
. It's just a group I have defined in my inventory.
This ansible_python_interpreter
only need for the first time, after that you can remove it because we have created the softlink for the python2.7
Hope that help you.
SOLOUTION#2
Reason of this error:
I have reviewed the gist that contain the detail log and figured out this:
- I am sure you are using the official vagrant box
ubuntu/xenial64
- This official vagrant box doesn't have
vagrant
user "msg": "chown failed: failed to look up user vagrant"
that's the error trace which help you find the exact error.
Solution-1 to this error:
Download some other vagrant box, I recommend this vagrant box geerlingguy/ubuntu1604
it has really good reputation
Solution-2 to this error:
With the official vagrant box, you can do the same as I am doing to mitigate this error. Add the following to your Vagrantfile
:
config.vm.provision "shell" do |s|
ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
ssh_user = ENV['USER']
s.inline = <<-SHELL
adduser --disabled-password --gecos "" #{ssh_user}
mkdir -p /home/#{ssh_user}/.ssh
touch /home/#{ssh_user}/.ssh/authorized_keys
chown -R #{ssh_user}. /home/#{ssh_user}/.ssh
echo "#{ssh_user} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/99-#{ssh_user}
echo #{ssh_pub_key} >> /home/#{ssh_user}/.ssh/authorized_keys
chmod 0440 /etc/sudoers.d/99-#{ssh_user}
SHELL
end
What it will do is, just create your host login user to the guest and upload the rsa key for it. So you can run the playbook to the vagrant machine as if it is the remote machine. If you'll face any problem further, please let me know.
Hope this help you.
这篇关于在 chown 上使用 Ansible 配置 Ubuntu 16.04 Vagrant 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!