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
This commit is contained in:
Jonathan Rosser 2020-02-19 11:48:49 +00:00
parent 4b4e7c7117
commit 5eeec731c4

View File

@ -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"