---
# 1. PRE-CLEANUP: Wipe out the "graveyard" of old migration folders
# This ensures that discovery doesn't see old v84, v85, etc. files.
- name: "Cleanup: Find all legacy migration directories in /tmp"
ansible.builtin.find:
paths: "/tmp"
patterns: "*-leonid-comet-lse-migration"
file_type: directory
register: old_migration_folders
- name: "Cleanup: Remove old migration staging areas"
ansible.builtin.file:
path: "{{ item.path }}"
state: absent
loop: "{{ old_migration_folders.files }}"
# Only delete if it's NOT the folder for the current execution
when: "lightspeed.build_version not in item.path"
become: yes
# 2. DISCOVERY & INSTALL (The logic that worked)
- name: "Discovery: Find the current RPM file"
ansible.builtin.find:
paths: "/tmp/{{ lightspeed.build_version }}"
patterns: "*.rpm"
register: found_rpms
- name: "Logic: Extract App/Region and Version"
ansible.builtin.set_fact:
app_prefix: "{{ (found_rpms.files[0].path | basename | regex_search('^([^-]+)-(.*)\\.x86_64\\.rpm$', '\\1'))[0] }}"
app_version: "{{ (found_rpms.files[0].path | basename | regex_search('^([^-]+)-(.*)\\.x86_64\\.rpm$', '\\2'))[0] }}"
when: found_rpms.matched > 0
- name: "Report: Show Discovered Metadata"
ansible.builtin.debug:
msg: "Deploying {{ app_prefix }} version {{ app_version }}"
- name: "Install: Unpack RPM via Built-in Module"
ansible.builtin.yum:
name: "{{ found_rpms.files[0].path }}"
state: present
disable_gpg_check: yes
become: yes
# 3. LINKING
- name: "Link: Create symlink to /opt/{{ app_prefix }}/{{ app_version }}"
ansible.builtin.file:
src: "/opt/{{ app_prefix }}/{{ app_version }}"
dest: "/opt/CPLS/live"
state: link
force: yes
become: yes
# 4. POST-CLEANUP: Delete current staging directory
# Corrected the 'path' and 'become' syntax from your OCR
- name: "Cleanup: Delete current staging directory"
ansible.builtin.file:
path: "/tmp/{{ lightspeed.build_version }}/"
state: absent
become: yes
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)