Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A more reliable way to detect Ubuntu #7524

Merged
merged 1 commit into from
Jul 19, 2016

Conversation

nishidayuya
Copy link
Contributor

lsb_release command is included in lsb-release package. Sometimes this is not installed; ex: Docker official Ubuntu image.

$ docker run --rm -it ubuntu:precise bash -l -c 'lsb_release -i'
bash: lsb_release: command not found
$ docker run --rm -it ubuntu:trusty bash -l -c 'lsb_release -i' 
Distributor ID: Ubuntu
$ docker run --rm -it ubuntu:xenial bash -l -c 'lsb_release -i'
bash: lsb_release: command not found

/etc/os-release is included in base-files package, so this is more reliable than lsb_release.

$ docker run --rm -it ubuntu:precise bash -l -c '. /etc/os-release && echo $ID'  
ubuntu
$ docker run --rm -it ubuntu:trusty bash -l -c '. /etc/os-release && echo $ID' 
ubuntu
$ docker run --rm -it ubuntu:xenial bash -l -c '. /etc/os-release && echo $ID'
ubuntu

This pull-request uses /etc/os-release for Ubuntu detection.

lsb_release command is included in lsb-release package. Sometimes this is
not installed; ex: Docker official Ubuntu image.
/etc/os-release is included in base-files package,
so this is more reliable than lsb_release.
@sethvargo sethvargo self-assigned this Jun 27, 2016
@sethvargo
Copy link
Contributor

I'll need to test this across multiple ubuntu versions

@nishidayuya
Copy link
Contributor Author

We can try following:

Setup

Requires Vagrant repository and Docker.

Creates following Vagrantfile.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
  config.vm.provider(:docker) do |d|
    d.image = "test_ubuntu"
    d.has_ssh = true
  end
end

Download Dockerfile via wget or curl.

Creates Docker image for Vagrant.

$ docker build -t test_ubuntu .

Before pull-request

Vagrant cannot detect Ubuntu (except Ubuntu Trusty).

$ bundle exec vagrant destroy -f
$ bundle exec vagrant up --provider=docker --debug 2> /tmp/before.log
$ sed -n -e '/^DEBUG guest: Trying: ubuntu/, /^DEBUG ssh: Exit status: / p' \
    /tmp/before.log
DEBUG guest: Trying: ubuntu
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: [ -x /usr/bin/lsb_release ] && /usr/bin/lsb_release -i 2>/dev/null | grep Ubuntu (sudo=false)
DEBUG ssh: Exit status: 1

After pull-request

Vagrant can detect Ubuntu.

$ bundle exec vagrant destroy -f
$ bundle exec vagrant up --provider=docker --debug 2> /tmp/after.log
$ sed -n -e '/^DEBUG guest: Trying: ubuntu/, /^DEBUG ssh: Exit status: / p' \
    /tmp/after.log
DEBUG guest: Trying: ubuntu
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: test -r /etc/os-release && . /etc/os-release && test xubuntu = x$ID (sudo=false)
DEBUG ssh: Exit status: 0

@sethvargo sethvargo merged commit 30692fc into hashicorp:master Jul 19, 2016
@nishidayuya nishidayuya deleted the fix_ubuntu_guest_detection branch July 19, 2016 10:11
@nishidayuya
Copy link
Contributor Author

sethvargo added a commit that referenced this pull request Jul 23, 2016
sethvargo added a commit that referenced this pull request Jul 23, 2016
carlosefr pushed a commit to carlosefr/vagrant that referenced this pull request Jul 25, 2016
@ghost ghost locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants