使用AnsibleconfigurationUbuntu 16.04 Vagrant失败

我正在尝试configurationAnsible的Ubuntu Xenial Vagrant客户端。 它在Ubuntu 14.04上正常工作,但在16.04上失败。 我得到的错误是

chown failed: failed to look up user vagrant

我正在运行的任务如下:

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

search没有find太多的帮助。

谢谢!

编辑:数字海洋14.04液滴进一步testing也显示这个问题。

编辑2: 完整的输出日志在-vvvv级别

SOLOUTION#1

Ubuntu 16.04有python3,而不是2.7.x. 而Ansible目前还不支持Python 3。

对于Ubuntu 16.04,我使用以下方法来安装Python 2.7。

 --- - 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在远程服务器上执行远程服务器还不支持的代码。如果没有这一行,则播放将失败。

这提供了一个/usr/bin/python2.7 ,我明确指出在我的库存文件中。

 [xenials] 192.168.33.100 [xenials:vars] ansible_python_interpreter=/usr/bin/python2.7 

请注意, xenials这个名字没有什么特别之处。 这只是我在库存中定义的一个组。

ansible_python_interpreter只需要第一次,之后,你可以删除它,因为我们已经创建了python2.7的软链接希望可以帮助你。

SOLOUTION#2

这个错误的原因是:

我已经审查了包含详细日志的要点,并想出了这个:

  • 我相信你使用的是官方的流浪盒ubuntu/xenial64
  • 这个官方的流浪者箱子没有vagrant用户 在这里输入图像说明
  • "msg": "chown failed: failed to look up user vagrant" ,这是错误追踪,帮助您找到确切的错误。

解决方案1到这个错误:

下载一些其他的流浪盒子,我推荐这个流浪盒geerlingguy/ubuntu1604它有很好的声誉

解决方案2到这个错误:

有了官方的流浪盒,你可以像我一样减轻这个错误。 将以下内容添加到您的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密钥。 所以你可以把游戏手册运行到流浪机器,就好像它是远程机器一样。 如果您还有任何问题,请告诉我。

希望这对你有所帮助。

我有同样的问题。 我正在使用ubuntu/xenial64

我注意到没有vagrant用户。 当我在使用Vagrant的SSH,使用ubuntu用户。

我创建了一个ansible.cnf

 [default] remote_user = ubuntu 

之后,我遇到了另一个问题:没有python。 我解决这个问题:

 sudo apt-get install python2.7 sudo apt-get install python-pip 

现在, ansible ping模块能够适用于我的主机。

 $ ansible elastichsearch -m ping 192.168,101.10 | SUCCESS => { "changed": false, "ping": "pong" }