diff --git a/content/debian-update-with-ansible.md b/content/debian-update-with-ansible.md index 6907a0a..4acf844 100644 --- a/content/debian-update-with-ansible.md +++ b/content/debian-update-with-ansible.md @@ -15,7 +15,7 @@ I figured I'd share the playbook I use to update the Debian packages ! I modified [this gist](https://gist.github.com/maethor/380676f6b1cec8cc7439) to only use apt-get instead of both apt-get and aptitude. ```yaml -- hosts: all +- hosts: debian remote_user: admin become: yes become_method: sudo @@ -23,7 +23,7 @@ I modified [this gist](https://gist.github.com/maethor/380676f6b1cec8cc7439) to - name: update cache apt: update_cache=yes - name: list packages to upgrade (1/2) - shell: apt-get upgrade --show-upgraded --assume-no | grep '^ ' | sed 's/ //;s/ /\n/g' + shell: apt-get upgrade --show-upgraded --assume-no | grep -A1 'The following packages will be upgraded:' | sed '1d;s/ //;s/ /\n/g' register: updates changed_when: False - name: list packages to upgrade (2/2) @@ -39,12 +39,22 @@ I modified [this gist](https://gist.github.com/maethor/380676f6b1cec8cc7439) to - name: notify distribution version upgrade debug: msg="Debian has been upgraded from {{ ansible_lsb.release }} to {{ new_release.stdout }}" when: ansible_lsb.release != new_release.stdout - - name: install the debian-goodies package if it is missing + - name: /wheezy/ install the debian-goodies package if it is missing apt: name=debian-goodies state=present - - name: list services to restart (1/2) + when: ansible_distribution_release == 'wheezy' + - name: /jessie/ install the needrestart package if it is missing + apt: name=needrestart state=present default_release=jessie-backports + when: ansible_distribution_release == 'jessie' + - name: /wheezy/ list services to restart (1/2) shell: checkrestart | grep ^service | awk '{print $2}' register: services changed_when: False + when: ansible_distribution_release == 'wheezy' + - name: /jessie/ list services to restart (1/2) + shell: needrestart -bl | grep ^NEEDRESTART-SVC | awk '{print $2}' + register: services + changed_when: False + when: ansible_distribution_release != 'wheezy' - name: list services to restart (2/2) debug: msg="{{ services.stdout_lines | count }} services to restart ({{ services.stdout_lines | join (', ') }})" when: (services.stdout_lines) diff --git a/output/debian-updates-with-ansible.html b/output/debian-updates-with-ansible.html index c0ec100..bf5d4a5 100644 --- a/output/debian-updates-with-ansible.html +++ b/output/debian-updates-with-ansible.html @@ -121,7 +121,7 @@

I figured I'd share the playbook I use to update the Debian packages !

The playbook

I modified this gist to only use apt-get instead of both apt-get and aptitude.

-
- hosts: all
+
- hosts: debian
   remote_user: admin
   become: yes
   become_method: sudo
@@ -129,7 +129,7 @@
     - name: update cache
       apt: update_cache=yes
     - name: list packages to upgrade (1/2)
-      shell: apt-get upgrade --show-upgraded --assume-no | grep '^ ' | sed 's/  //;s/ /\n/g'
+      shell: apt-get upgrade --show-upgraded --assume-no | grep -A1 'The following packages will be upgraded:' | sed '1d;s/  //;s/ /\n/g'
       register: updates
       changed_when: False
     - name: list packages to upgrade (2/2)
@@ -145,12 +145,22 @@
     - name: notify distribution version upgrade
       debug: msg="Debian has been upgraded from {{ ansible_lsb.release }} to {{ new_release.stdout }}"
       when: ansible_lsb.release != new_release.stdout
-    - name: install the debian-goodies package if it is missing
+    - name: /wheezy/ install the debian-goodies package if it is missing
       apt: name=debian-goodies state=present
-    - name: list services to restart (1/2)
+      when: ansible_distribution_release == 'wheezy'
+    - name: /jessie/ install the needrestart package if it is missing
+      apt: name=needrestart state=present default_release=jessie-backports
+      when: ansible_distribution_release == 'jessie'
+    - name: /wheezy/ list services to restart (1/2)
       shell: checkrestart | grep ^service | awk '{print $2}'
       register: services
       changed_when: False
+      when: ansible_distribution_release == 'wheezy'
+    - name: /jessie/ list services to restart (1/2)
+      shell: needrestart -bl | grep ^NEEDRESTART-SVC | awk '{print $2}'
+      register: services
+      changed_when: False
+      when: ansible_distribution_release != 'wheezy'
     - name: list services to restart (2/2)
       debug: msg="{{ services.stdout_lines | count }} services to restart ({{ services.stdout_lines | join (', ') }})"
       when: (services.stdout_lines)
diff --git a/output/rss.xml b/output/rss.xml
index 6748a36..a403a60 100644
--- a/output/rss.xml
+++ b/output/rss.xml
@@ -631,7 +631,7 @@ bind '"' choose-window
 <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></span><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>
+<div class="highlight"><pre><span></span><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">debian</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>
@@ -639,7 +639,7 @@ bind &#39;&quot;&#39; choose-window
     <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 &#39;^ &#39; | sed &#39;s/  //;s/ /\n/g&#39;</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 -A1 &#39;The following packages will be upgraded:&#39; | sed &#39;1d;s/  //;s/ /\n/g&#39;</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>
@@ -655,12 +655,22 @@ bind &#39;&quot;&#39; choose-window
     <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=&quot;Debian has been upgraded from {{ ansible_lsb.release }} to {{ new_release.stdout }}&quot;</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="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">/wheezy/ 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">when</span><span class="p p-Indicator">:</span> <span class="l l-Scalar l-Scalar-Plain">ansible_distribution_release == &#39;wheezy&#39;</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">/jessie/ install the needrestart 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=needrestart state=present default_release=jessie-backports</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_distribution_release == &#39;jessie&#39;</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">/wheezy/ 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 &#39;{print $2}&#39;</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="l l-Scalar l-Scalar-Plain">when</span><span class="p p-Indicator">:</span> <span class="l l-Scalar l-Scalar-Plain">ansible_distribution_release == &#39;wheezy&#39;</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">/jessie/ 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">needrestart -bl | grep ^NEEDRESTART-SVC | awk &#39;{print $2}&#39;</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="l l-Scalar l-Scalar-Plain">when</span><span class="p p-Indicator">:</span> <span class="l l-Scalar l-Scalar-Plain">ansible_distribution_release != &#39;wheezy&#39;</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=&quot;{{ services.stdout_lines | count }} services to restart ({{ services.stdout_lines | join (&#39;, &#39;) }})&quot;</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>