From 56a388eb38c7d61531836078e2dc3bae5f3b9538 Mon Sep 17 00:00:00 2001 From: Major Hayden Date: Fri, 11 Aug 2017 09:48:44 -0500 Subject: [PATCH] Fix python prereq install task It's not possible to check ansible_pkg_mgr yet because we haven't gathered facts. This patch adjusts the task to run on all distros but it only has an effect on Ubuntu systems without python installed. Change-Id: I8859b740a4d190fb1548af7ed7df92c248e2c5a3 --- playbooks/openstack-hosts-setup.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/playbooks/openstack-hosts-setup.yml b/playbooks/openstack-hosts-setup.yml index 0559529387..972ca3166c 100644 --- a/playbooks/openstack-hosts-setup.yml +++ b/playbooks/openstack-hosts-setup.yml @@ -13,6 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +# NOTE(mhayden): CentOS always has python (because of yum), but it's possible +# that Ubuntu nodes may not have python by default. Ansible doesn't work very +# well if Python isn't installed. +# +# Also, we can't use a 'when' to check for the ansible_pkg_mgr here because +# we haven't gathered facts yet. - name: Install Ansible prerequisites hosts: "{{ openstack_host_group|default('hosts') }}" gather_facts: false @@ -20,9 +26,13 @@ pre_tasks: - name: Ensure python is installed register: result - raw: apt-get -y install python - when: - - ansible_pkg_mgr == 'apt' + raw: | + if which apt-get >/dev/null && ! which python >/dev/null ; then + apt-get -y install python + exit 2 + else + exit 0 + fi changed_when: "result.rc == 2" failed_when: "{{ result.rc not in [0, 2] }}"