Skip to content

Instantly share code, notes, and snippets.

@trashhalo
Last active December 23, 2015 16:49
Show Gist options
  • Save trashhalo/6664262 to your computer and use it in GitHub Desktop.
Save trashhalo/6664262 to your computer and use it in GitHub Desktop.
Adds a new apt source to the sources.list.d. Runs apt-get update for only that source and installs a package from the new source.
define apt-update-single($repofile=$title,$source){
file{"/etc/apt/sources.list.d/${repofile}.list":
ensure=>'present',
content=>$source,
}
exec{"apt-get-update-$repofile":
command=>"/usr/bin/apt-get update -o Dir::Etc::sourcelist=\"sources.list.d/${repofile}.list\" -o Dir::Etc::sourceparts=\"-\" -o APT::Get::List-Cleanup=\"0\"",
require=>File["/etc/apt/sources.list.d/${repofile}.list"],
unless=>"/bin/ls /var/lib/apt/lists/|grep $repofile 2>/dev/null"
}
}
apt-update-single{'sublime':
source=>'deb http://ppa.launchpad.net/webupd8team/sublime-text-2/ubuntu raring main'
}
package{'sublime-text':
ensure => 'present',
require => Apt-update-single['sublime']
}
@trashhalo
Copy link
Author

unless=>"/bin/ls /var/lib/apt/lists/|grep $repofile 2>/dev/null"
I still feel iffy about that line. Its works in the two cases I am using it for but I am sure it wont for all cases. It looks in the place that ubuntu dumps its package databases to try and guess if this repository had previously been apt-get updated. If it sees the file with the matching name it skips it. This lets me keep reprovisioning down to 0.38 seconds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment