用Ansible设置Ubuntu 16.04 Vagrant在chown上失败 [英] Provisioning Ubuntu 16.04 Vagrant with Ansible fails on chown

查看:241
本文介绍了用Ansible设置Ubuntu 16.04 Vagrant在chown上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Ansible提供Ubuntu Xenial Vagrant来宾.它在Ubuntu 14.04上正常工作,但在16.04上失败.我得到的错误是

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 }}"

- name: Ensure /srv/web exists become: yes file: path: /srv/web state: directory mode: 0755 owner: "{{ remote_user }}"

搜索没有太大帮助.

谢谢!

在Digital Ocean 14.04小滴上进行的进一步测试也显示了此问题.

Further testing on a Digital Ocean 14.04 droplet also shows this issue.

-vvvv级别的完整的输出日志

推荐答案

SOLOUTION#1

Ubuntu 16.04具有python3,而不是2.7.x.并且Ansible尚不支持Python 3.

Ubuntu 16.04 has python3, not 2.7.x. and Ansible doesn't support for Python 3 yet.

对于Ubuntu 16.04,我使用以下代码来安装Python 2.7.

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

关键行是gather_facts: no,它阻止Ansible在远程服务器尚不支持的远程服务器上执行代码.如果没有此行,则播放将失败.

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.

这提供了一个/usr/bin/python2.7,我在库存文件中明确指向了该目录.

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 

请注意,名称xenials没有什么特别的.这只是我在广告资源中定义的一组.

Note that there is nothing special about the name xenials. It's just a group I have defined in my inventory.

只需ansible_python_interpreter第一次,之后您就可以将其删除,因为我们已经为python2.7创建了软链接 希望对您有帮助.

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.

解决方案#2

此错误的原因:

我已经查看了包含详细日志的要点,并弄清了这一点:

I have reviewed the gist that contain the detail log and figured out this:

  • 我确定您正在使用官方的无业游民箱ubuntu/xenial64
  • 这个官方的无家可归的盒子没有vagrant用户
  • "msg": "chown failed: failed to look up user vagrant"是错误跟踪,可以帮助您找到确切的错误.
  • 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.

解决方案1,此错误:

下载其他流浪者盒子,我推荐这个流浪者盒子geerlingguy/ubuntu1604它的口碑很好

Download some other vagrant box, I recommend this vagrant box geerlingguy/ubuntu1604 it has really good reputation

此错误的解决方案2:

使用官方的Vagrant框,您可以执行与我为减轻此错误所做的相同的操作.将以下内容添加到您的Vagrantfile:

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

它将要做的是,只需将您的主机登录用户创建给来宾,然后为其上传rsa密钥.因此,您可以将剧本运行到无所事事的计算机上,就像它是远程计算机一样.如果您再遇到任何问题,请告诉我.

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.

希望这对您有所帮助.

这篇关于用Ansible设置Ubuntu 16.04 Vagrant在chown上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆