Provisioning Ubuntu 16.04 Vagrant with Ansible fails on chown
NickName:Zooey Ask DateTime:2016-06-14T10:58:23

Provisioning Ubuntu 16.04 Vagrant with Ansible fails on chown

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

Copyright Notice:Content Author:「Zooey」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/37802230/provisioning-ubuntu-16-04-vagrant-with-ansible-fails-on-chown

Answers
Arbab Nazar 2016-06-14T08:41:29

SOLOUTION#1\n\nUbuntu 16.04 has python3, not 2.7.x. and Ansible doesn't support for Python 3 yet.\n\nFor Ubuntu 16.04 I use the following play to get Python 2.7 installed. \n\n---\n- hosts: xenials \n gather_facts: no\n become: yes\n tasks:\n - name: Install python 2.7 \n raw: apt-get update -qq && apt-get install -qq python2.7\n\n - name: check if softlink exists\n stat:\n path: /usr/bin/python\n register: python_file\n\n - name: create softlink for python 2.7\n raw: ln -s /usr/bin/python2.7 /usr/bin/python\n when: python_file.stat.islnk is not defined\n\n - name: Ensure /srv/web exists\n file:\n path: /srv/web\n state: directory\n mode: 0755\n owner: \"{{ remote_user }}\" # hope you have defined this variable in your ansible.cfg\n\n\nkey 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. \n\nThat provides an /usr/bin/python2.7, which I explicitly point to in my inventory file. \n\n[xenials] \n192.168.33.100 \n\n[xenials:vars] \nansible_python_interpreter=/usr/bin/python2.7 \n\n\nNote that there is nothing special about the name xenials. It's just a group I have defined in my inventory. \n\nThis 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\nHope that help you.\n\nSOLOUTION#2\n\nReason of this error:\n\nI have reviewed the gist that contain the detail log and figured out this:\n\n\nI am sure you are using the official vagrant box ubuntu/xenial64\nThis official vagrant box doesn't have vagrant user\n\n\"msg\": \"chown failed: failed to look up user vagrant\" that's the error trace which help you find the exact error.\n\n\nSolution-1 to this error:\n\nDownload some other vagrant box, I recommend this vagrant box geerlingguy/ubuntu1604 it has really good reputation\n\nSolution-2 to this error:\n\nWith the official vagrant box, you can do the same as I am doing to mitigate this error. Add the following to your Vagrantfile:\n\nconfig.vm.provision \"shell\" do |s|\n ssh_pub_key = File.readlines(\"#{Dir.home}/.ssh/id_rsa.pub\").first.strip\n ssh_user = ENV['USER']\n s.inline = <<-SHELL\n adduser --disabled-password --gecos \"\" #{ssh_user}\n mkdir -p /home/#{ssh_user}/.ssh\n touch /home/#{ssh_user}/.ssh/authorized_keys\n chown -R #{ssh_user}. /home/#{ssh_user}/.ssh\n echo \"#{ssh_user} ALL=(ALL) NOPASSWD:ALL\" > /etc/sudoers.d/99-#{ssh_user}\n echo #{ssh_pub_key} >> /home/#{ssh_user}/.ssh/authorized_keys\n chmod 0440 /etc/sudoers.d/99-#{ssh_user}\n SHELL\n end\n\n\nWhat 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.\n\nHope this help you.",


More about “Provisioning Ubuntu 16.04 Vagrant with Ansible fails on chown” related questions

Provisioning Ubuntu 16.04 Vagrant with Ansible fails on chown

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 ...

Show Detail

Vagrant with Ansible Provisioning - How to git clone private repo

I am using Vagrant to setup a shared development server. I am trying to use Ansible for the provisioning (having previously used bash scripts). I can't seem to correctly configure things so Ansible...

Show Detail

Ubuntu error with ansible provisioning

This may be something very simple. I am running provisioning with ansible-playbook on Ubuntu 12.04: ansible-playbook web.yml and getting the following error: ERROR: The file ./hosts is marked as

Show Detail

Ansible called by Vagrant does not prompt for vault password

Summary I have a Vagrantfile provisioning a Virtualbox VM with Ansible. The Ansible playbook contains an Ansible Vault-encrypted variable. My problem is that Vagrant provisioning does not prompt f...

Show Detail

Ansible on Ubuntu 16.04 error on ping command

I have a vagrant Ubuntu 16.04 VM with Ansible installed (using sudo apt install ansible) i config the /etc/ansible/hosts file and when i try to run ansible all -m ping i get this error: Traceback ...

Show Detail

Unable to connect to ubuntu 16.04 using ansible

I am using ansible playbook to create new AWS EC2 instance. I am running my playook from host1 and then want to run some tasks on newly created EC2 instance (host2). I am able to run all the ansible

Show Detail

vagrant with ubuntu 16.04

I have installed vagrant and up a machine with config.vm.box = "hashicorp/precise64" When I check the linux specs, It was showing ubuntu 12 I want to install ubuntu 16.04 what should I do now ?

Show Detail

Access Box Name When Using Ansible for Vagrant Provisioning

I'm trying to do provisioning for a Vagrant multimachine setup with Ansible. I've got it installing the software I was after, but I want to be able to load in machine specific configuration it can ...

Show Detail

Upgrading Vagrant in Ubuntu 16.04

I currently have Vagrant 1.8.1 installed in my Ubuntu 16.04 I'm thinking to upgrade it to Vagrant 2.0.0 The problem is I'm not sure if my vagrant files and VMs gets removed if I directly install

Show Detail

Vagrant shell and ansible provisioning fail with bitbucket

I can't force vagrant provisioning to clone private git repos from bitbucket. I have vagrant 1.6.3. Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.ssh.private_key_path = "~/.vag...

Show Detail