From 5eeec731c48839123249a8bed9b1de56963475aa Mon Sep 17 00:00:00 2001 From: Jonathan Rosser Date: Wed, 19 Feb 2020 11:48:49 +0000 Subject: [PATCH] Ensure utility binaries link to the latest versions The previous code would not move the openstack cli symlinks from old venv to new ones at either minor or major release upgrades. This patch changes the code to use a native ansible module instead of shell commands. The symlinks are now moved to the current venv and the tasks are idempotent. Change-Id: If10f83814d1934b430749a33efdbf20408e2fa3d --- playbooks/utility-install.yml | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/playbooks/utility-install.yml b/playbooks/utility-install.yml index 5d83f74fae..27d83e57c2 100644 --- a/playbooks/utility-install.yml +++ b/playbooks/utility-install.yml @@ -127,20 +127,23 @@ - "--constraint {{ utility_upper_constraints_url }}" venv_pip_packages: "{{ _openstack_client_list | union(utility_pip_packages) }}" + - name: Create list of binaries to symlink + set_fact: + _openstack_client_to_symlink: >- + {%- set binary_list = [] %} + {%- for l in _openstack_client_list %} + {%- set _ = binary_list.append(l | regex_replace('^(?:python-)?(\w*)(?:client)$', '\\1')) %} + {%- endfor %} + {{- binary_list }} + run_once: true + - name: Create symlinks for openstack clients - shell: | - {% set _bin_name = item | regex_replace('^(?:python-)?(\w*)(?:client)$', '\\1') %} - set -e - return_code=0 - if [[ -e "{{ utility_venv_bin }}/{{ _bin_name }}" && ! -L "/usr/local/bin/{{ _bin_name }}" ]]; then - ln -sfn {{ utility_venv_bin }}/{{ _bin_name }} /usr/local/bin/{{ _bin_name }} - return_code=2 - fi - exit ${return_code} - args: - executable: /bin/bash - with_items: "{{ _openstack_client_list }}" - register: _client_symlink - changed_when: _client_symlink.rc == 2 - failed_when: _client_symlink.rc not in [0,2] + file: + src: "{{ utility_venv_bin }}/{{ item }}" + path: "/usr/local/bin/{{ item }}" + state: link + force: yes + follow: false + with_items: + - "{{ _openstack_client_to_symlink }}" notify: "Create openstack client bash_completion script"