|
| 1 | +# Cookbook Name:: travis_build_environment |
| 2 | +# Recipe:: hostname |
| 3 | +# Copyright 2011-2015, Travis CI GmbH <[email protected]> |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in |
| 13 | +# all copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 21 | +# THE SOFTWARE. |
| 22 | + |
| 23 | +include_recipe 'travis_build_environment::cloud_init' |
| 24 | + |
| 25 | +bits = (node.kernel.machine =~ /x86_64/ ? 64 : 32) |
| 26 | +hostname = case [node[:platform], node[:platform_version]] |
| 27 | + when ["ubuntu", "11.04"] then |
| 28 | + "natty#{bits}" |
| 29 | + when ["ubuntu", "11.10"] then |
| 30 | + "oneiric#{bits}" |
| 31 | + when ["ubuntu", "12.04"] then |
| 32 | + "precise#{bits}" |
| 33 | + end |
| 34 | + |
| 35 | +template "/etc/hosts" do |
| 36 | + owner "root" |
| 37 | + group "root" |
| 38 | + mode 0644 |
| 39 | + variables(:hostname => hostname) |
| 40 | + source "etc/hosts.erb" |
| 41 | + not_if { !node[:travis_build_environment][:update_hosts] } |
| 42 | +end |
| 43 | + |
| 44 | +%w( |
| 45 | + /etc/cloud/templates/hosts.debian.tmpl |
| 46 | + /etc/cloud/templates/hosts.tmpl |
| 47 | + /etc/cloud/templates/hosts.ubuntu.tmpl |
| 48 | +).each do |filename| |
| 49 | + template filename do |
| 50 | + source 'etc/cloud/templates/hosts.tmpl.erb' |
| 51 | + owner 'root' |
| 52 | + group 'root' |
| 53 | + mode 0644 |
| 54 | + variables(hostname: hostname) |
| 55 | + end |
| 56 | +end |
| 57 | + |
| 58 | +template "/etc/hostname" do |
| 59 | + owner "root" |
| 60 | + group "root" |
| 61 | + mode 0644 |
| 62 | + variables(:hostname => hostname) |
| 63 | + source "etc/hostname.erb" |
| 64 | + not_if { !node[:travis_build_environment][:update_hosts] } |
| 65 | +end |
| 66 | + |
| 67 | +execute "hostname #{hostname}" do |
| 68 | + user "root" |
| 69 | +end |
0 commit comments