2016-01-31 15:19:29 +01:00
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "utf-8" >
< meta http-equiv = "X-UA-Compatible" content = "IE=edge" >
< meta name = "viewport" content = "width=device-width, initial-scale=1" >
< meta name = "description" content = "" >
< meta name = "author" content = "" >
2016-01-31 15:44:13 +01:00
< title > Debian updates with Ansible< / title >
2016-01-31 15:19:29 +01:00
2016-01-31 16:10:48 +01:00
< link href = "https://captainark.net/rss.xml" type = "application/atom+xml" rel = "alternate" title = "Sysadmining. All day. Every day. Full Atom Feed" / >
2016-01-31 15:19:29 +01:00
<!-- Bootstrap Core CSS -->
< link href = "https://captainark.net/theme/css/bootstrap.min.css" rel = "stylesheet" >
<!-- Custom CSS -->
< link href = "https://captainark.net/theme/css/clean-blog.min.css" rel = "stylesheet" >
<!-- Code highlight color scheme -->
< link href = "https://captainark.net/theme/css/code_blocks/github.css" rel = "stylesheet" >
<!-- Custom Fonts -->
< link href = "https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel = "stylesheet" type = "text/css" >
< link href = 'https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel = 'stylesheet' type = 'text/css' >
< link href = 'https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel = 'stylesheet' type = 'text/css' >
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!-- [if lt IE 9]>
< script src = "https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js" > < / script >
< script src = "https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js" > < / script >
<![endif]-->
< meta property = "og:locale" content = "" >
< meta property = "og:site_name" content = "Sysadmining. All day. Every day." >
< meta property = "og:type" content = "article" >
< meta property = "article:author" content = "" >
2016-01-31 15:44:13 +01:00
< meta property = "og:url" content = "https://captainark.net/debian-updates-with-ansible.html" >
< meta property = "og:title" content = "Debian updates with Ansible" >
2016-01-31 15:19:29 +01:00
< meta property = "og:description" content = "" >
< meta property = "og:image" content = "https://captainark.net/" >
< meta property = "article:published_time" content = "2016-01-31 00:00:00+01:00" >
< / head >
< body >
<!-- Navigation -->
< nav class = "navbar navbar-default navbar-custom navbar-fixed-top" >
< div class = "container-fluid" >
<!-- Brand and toggle get grouped for better mobile display -->
< div class = "navbar-header page-scroll" >
< button type = "button" class = "navbar-toggle" data-toggle = "collapse" data-target = "#bs-example-navbar-collapse-1" >
< span class = "sr-only" > Toggle navigation< / span >
< span class = "icon-bar" > < / span >
< span class = "icon-bar" > < / span >
< span class = "icon-bar" > < / span >
< / button >
< a class = "navbar-brand" href = "https://captainark.net/" > Sysadmining. All day. Every day.< / a >
< / div >
<!-- Collect the nav links, forms, and other content for toggling -->
< div class = "collapse navbar-collapse" id = "bs-example-navbar-collapse-1" >
< ul class = "nav navbar-nav navbar-right" >
< li > < a href = "/" > Homepage< / a > < / li >
2016-01-31 16:10:48 +01:00
< li > < a href = "/rss.xml" > RSS< / a > < / li >
2016-01-31 15:19:29 +01:00
< li > < a href = "/categories.html" > Categories< / a > < / li >
< li > < a href = "https://captainark.net/pages/about.html" > About< / a > < / li >
< li > < a href = "https://captainark.net/pages/resume.html" > Resume< / a > < / li >
< / ul >
< / div >
<!-- /.navbar - collapse -->
< / div >
<!-- /.container -->
< / nav >
<!-- Page Header -->
< header class = "intro-header" style = "background-image: url('/bg.png')" >
< div class = "container" >
< div class = "row" >
< div class = "col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1" >
< div class = "post-heading" >
2016-01-31 15:44:13 +01:00
< h1 > Debian updates with Ansible< / h1 >
2016-01-31 15:19:29 +01:00
< span class = "meta" > Posted by
< a href = "https://captainark.net/author/antoine-joubert.html" > Antoine Joubert< / a >
on Sun 31 January 2016
< / span >
< / div >
< / div >
< / div >
< / div >
< / header >
<!-- Main Content -->
< div class = "container" >
< div class = "row" >
< div class = "col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1" >
<!-- Post Content -->
< article >
2016-01-31 16:01:02 +01:00
< p > I've recently bought a < a href = "http://www8.hp.com/us/en/products/proliant-servers/product-detail.html?oid=5379860" > HP Proliant Microserver Gen8< / a > to play around with LXC and try new stuff.< / p >
2016-01-31 15:19:29 +01:00
< p > From the 4 Debian machines I had to keep up-to-date, I now have 7, so it became quite time-consumming to manually SSH to each of them whenever an update became available.< / p >
2016-01-31 15:44:13 +01:00
< p > I ended up looking at < a href = "http://www.ansible.com/" > Ansible< / a > to speed up the process and, within an hour, I had a working playbook that updates the debian packages, pip packages and git repos installed on all of my servers with a single command.< / p >
2016-01-31 15:19:29 +01:00
< p > I figured I'd share the playbook I use to update the Debian packages !< / p >
< h2 > The playbook< / h2 >
< p > I modified < a href = "https://gist.github.com/maethor/380676f6b1cec8cc7439" > this gist< / a > to only use apt-get instead of both apt-get and aptitude.< / p >
< div class = "highlight" > < pre > < span class = "p p-Indicator" > -< / span > < span class = "l l-Scalar l-Scalar-Plain" > hosts< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > all< / span >
< span class = "l l-Scalar l-Scalar-Plain" > remote_user< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > admin< / span >
< span class = "l l-Scalar l-Scalar-Plain" > become< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > yes< / span >
< span class = "l l-Scalar l-Scalar-Plain" > become_method< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > sudo< / span >
< span class = "l l-Scalar l-Scalar-Plain" > tasks< / span > < span class = "p p-Indicator" > :< / span >
< span class = "p p-Indicator" > -< / span > < span class = "l l-Scalar l-Scalar-Plain" > name< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > update cache< / span >
< span class = "l l-Scalar l-Scalar-Plain" > apt< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > update_cache=yes< / span >
< span class = "p p-Indicator" > -< / span > < span class = "l l-Scalar l-Scalar-Plain" > name< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > list packages to upgrade (1/2)< / span >
< span class = "l l-Scalar l-Scalar-Plain" > shell< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > apt-get upgrade --show-upgraded --assume-no | grep ' ^ ' | sed ' s/ //;s/ /\n/g' < / span >
< span class = "l l-Scalar l-Scalar-Plain" > register< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > updates< / span >
< span class = "l l-Scalar l-Scalar-Plain" > changed_when< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > False< / span >
< span class = "p p-Indicator" > -< / span > < span class = "l l-Scalar l-Scalar-Plain" > name< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > list packages to upgrade (2/2)< / span >
< span class = "l l-Scalar l-Scalar-Plain" > debug< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > msg=" {{ updates.stdout_lines | count }} packages to upgrade ({{ updates.stdout_lines | join(' , ' ) }})" < / span >
< span class = "l l-Scalar l-Scalar-Plain" > when< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > (updates.stdout_lines)< / span >
< span class = "p p-Indicator" > -< / span > < span class = "l l-Scalar l-Scalar-Plain" > name< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > upgrade packages< / span >
< span class = "l l-Scalar l-Scalar-Plain" > apt< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > upgrade=dist< / span >
2016-01-31 15:44:13 +01:00
< span class = "l l-Scalar l-Scalar-Plain" > when< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > (updates.stdout_lines)< / span >
2016-01-31 15:19:29 +01:00
< span class = "p p-Indicator" > -< / span > < span class = "l l-Scalar l-Scalar-Plain" > name< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > check what the new version is< / span >
< span class = "l l-Scalar l-Scalar-Plain" > shell< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > lsb_release -r | awk ' {print $2}' < / span >
< span class = "l l-Scalar l-Scalar-Plain" > changed_when< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > False< / span >
< span class = "l l-Scalar l-Scalar-Plain" > register< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > new_release< / span >
< span class = "p p-Indicator" > -< / span > < span class = "l l-Scalar l-Scalar-Plain" > name< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > notify distribution version upgrade< / span >
< span class = "l l-Scalar l-Scalar-Plain" > debug< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > msg=" Debian has been upgraded from {{ ansible_lsb.release }} to {{ new_release.stdout }}" < / span >
< span class = "l l-Scalar l-Scalar-Plain" > when< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > ansible_lsb.release != new_release.stdout< / span >
< span class = "p p-Indicator" > -< / span > < span class = "l l-Scalar l-Scalar-Plain" > name< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > install the debian-goodies package if it is missing< / span >
< span class = "l l-Scalar l-Scalar-Plain" > apt< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > name=debian-goodies state=present< / span >
< span class = "p p-Indicator" > -< / span > < span class = "l l-Scalar l-Scalar-Plain" > name< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > list services to restart (1/2)< / span >
< span class = "l l-Scalar l-Scalar-Plain" > shell< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > checkrestart | grep ^service | awk ' {print $2}' < / span >
< span class = "l l-Scalar l-Scalar-Plain" > register< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > services< / span >
< span class = "l l-Scalar l-Scalar-Plain" > changed_when< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > False< / span >
< span class = "p p-Indicator" > -< / span > < span class = "l l-Scalar l-Scalar-Plain" > name< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > list services to restart (2/2)< / span >
< span class = "l l-Scalar l-Scalar-Plain" > debug< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > msg=" {{ services.stdout_lines | count }} services to restart ({{ services.stdout_lines | join (' , ' ) }})" < / span >
< span class = "l l-Scalar l-Scalar-Plain" > when< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > (services.stdout_lines)< / span >
< span class = "p p-Indicator" > -< / span > < span class = "l l-Scalar l-Scalar-Plain" > name< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > cache cleanup< / span >
< span class = "l l-Scalar l-Scalar-Plain" > shell< / span > < span class = "p p-Indicator" > :< / span > < span class = "l l-Scalar l-Scalar-Plain" > apt-get autoclean< / span >
< / pre > < / div >
< h2 > Conclusion< / h2 >
< p > That's all ! Please leave a comment if you've found this playbook helpful !< / p >
< / article >
< hr >
< div class = "sharing" >
< / div >
< hr >
< div class = "comments" >
< h2 > Comments !< / h2 >
< div id = "disqus_thread" > < / div >
< script type = "text/javascript" >
var disqus_shortname = 'captainark';
2016-01-31 15:44:13 +01:00
var disqus_identifier = 'debian-updates-with-ansible.html';
var disqus_url = 'https://captainark.net/debian-updates-with-ansible.html';
2016-01-31 15:19:29 +01:00
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//captainark.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
< / script >
< noscript > Please enable JavaScript to view the comments.< / noscript >
< / div >
< / div >
< / div >
< / div >
< hr >
<!-- Footer -->
< footer >
< div class = "container" >
< div class = "row" >
< div class = "col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1" >
< ul class = "list-inline text-center" >
< li >
< a href = "mailto:contact@captainark.net" >
< span class = "fa-stack fa-lg" >
< i class = "fa fa-circle fa-stack-2x" > < / i >
< i class = "fa fa-envelope fa-stack-1x fa-inverse" > < / i >
< / span >
< / a >
< / li >
< li >
< a href = "https://twitter.com/captainark" >
< span class = "fa-stack fa-lg" >
< i class = "fa fa-circle fa-stack-2x" > < / i >
< i class = "fa fa-twitter fa-stack-1x fa-inverse" > < / i >
< / span >
< / a >
< / li >
< li >
< a href = "https://github.com/captainark" >
< span class = "fa-stack fa-lg" >
< i class = "fa fa-circle fa-stack-2x" > < / i >
< i class = "fa fa-github fa-stack-1x fa-inverse" > < / i >
< / span >
< / a >
< / li >
< li >
< a href = "http://www.last.fm/user/captainark" >
< span class = "fa-stack fa-lg" >
< i class = "fa fa-circle fa-stack-2x" > < / i >
< i class = "fa fa-lastfm fa-stack-1x fa-inverse" > < / i >
< / span >
< / a >
< / li >
< li >
< a href = "https://steamcommunity.com/id/captainark" >
< span class = "fa-stack fa-lg" >
< i class = "fa fa-circle fa-stack-2x" > < / i >
< i class = "fa fa-steam fa-stack-1x fa-inverse" > < / i >
< / span >
< / a >
< / li >
< li >
< a href = "http://www.twitch.tv/captainark" >
< span class = "fa-stack fa-lg" >
< i class = "fa fa-circle fa-stack-2x" > < / i >
< i class = "fa fa-twitch fa-stack-1x fa-inverse" > < / i >
< / span >
< / a >
< / li >
< / ul >
< p class = "copyright text-muted" >
Blog powered by < a href = "http://getpelican.com" > Pelican< / a > ,
which takes great advantage of < a href = "http://python.org" > Python< / a > .
< / p > < / div >
< / div >
< / div >
< / footer >
<!-- jQuery -->
< script src = "https://captainark.net/theme/js/jquery.js" > < / script >
<!-- Bootstrap Core JavaScript -->
< script src = "https://captainark.net/theme/js/bootstrap.min.js" > < / script >
<!-- Custom Theme JavaScript -->
< script src = "https://captainark.net/theme/js/clean-blog.min.js" > < / script >
2016-01-31 16:10:48 +01:00
< script type = "text/javascript" >
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-53658366-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
< / script >
2016-01-31 15:19:29 +01:00
< script type = "text/javascript" >
var disqus_shortname = 'captainark';
(function () {
var s = document.createElement('script'); s.async = true;
s.type = 'text/javascript';
s.src = '//' + disqus_shortname + '.disqus.com/count.js';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
< / script >
< / body >
< / html >