From 2cfd85c792c1635f728dade92fd789eb28432c61 Mon Sep 17 00:00:00 2001
From: Clark Boylan <clark.boylan@gmail.com>
Date: Fri, 8 Mar 2019 09:04:11 -0800
Subject: [PATCH] Only install puppet 4 if not already installed

The reinstallation of puppet 4 on every ansible run was assumed to be a
non issue that we could disable after our complete conversion to puppet
4 (via removal of the explicit install playbook and reliance on our
launch tooling). However, Installation of this package actually causes
the removal of Gerrit rc.d files which the next puppet run reinstalls.

Avoid this back and forth and the unnecesasry additional package
installation by checking if the puppet 4 bin path exists prior to
reinstalling puppet 4.

Change-Id: I47821ae799412f6cb9693b617ae6e7e630590c15
---
 playbooks/update_puppet_version.yaml | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/playbooks/update_puppet_version.yaml b/playbooks/update_puppet_version.yaml
index b69edd5d3c..bc455d04d0 100644
--- a/playbooks/update_puppet_version.yaml
+++ b/playbooks/update_puppet_version.yaml
@@ -2,11 +2,19 @@
   name: "Puppet-version: install puppet-4 on puppet-4 hosts"
   gather_facts: false
   tasks:
-  - get_url:
+  - name: "Check if puppet 4 is already installed"
+    stat:
+      path: /opt/puppetlabs/puppet/bin/puppet
+    register: puppet4_bin_path
+  - name: "Get puppet installation script"
+    get_url:
       url: http://git.openstack.org/cgit/openstack-infra/system-config/plain/install_puppet.sh
       dest: /tmp/install_puppet.sh
       mode: 0755
       checksum: sha256:741b8cfdc039e817bd598511dd7203da16701f213775e639994e8bb278a68239
-  - shell: /tmp/install_puppet.sh
+    when: not puppet4_bin_path.stat.exists
+  - name: "Install puppet 4 if not already installed"
+    shell: /tmp/install_puppet.sh
     environment:
       PUPPET_VERSION: 4
+    when: not puppet4_bin_path.stat.exists