DEV Community

Query Filter
Query Filter

Posted on

docker28

---
# 1. Discovery: Find the physical RPM file
- name: "Discovery: Find the RPM file in the migration directory"
  ansible.builtin.find:
    paths: "/tmp/{{ lightspeed.build_version }}"
    patterns: "*.rpm"
  register: found_rpms

# 2. Logic: Extract Prefix and Version
- name: "Logic: Extract Metadata from RPM Filename"
  ansible.builtin.set_fact:
    # Extracts everything before the first hyphen as 'app_prefix'
    # Extracts everything between the first hyphen and '.x86_64' as 'app_version'
    rpm_filename: "{{ found_rpms.files[0].path | basename }}"
    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

# 3. Report: Show extracted metadata
- name: "Report: Show Discovered Deployment Metadata"
  ansible.builtin.debug:
    msg: 
      - "Full RPM Filename: {{ rpm_filename }}"
      - "Detected App/Region: {{ app_prefix }}"
      - "Detected Version: {{ app_version }}"

# 4. Installation: Automatic Unpack via YUM
- 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

# 5. Link: Dynamic Symlink Creation
# If app_prefix is CPLSEMEA, it links to /opt/CPLSEMEA/{{ version }}
# If app_prefix is CPLS, it links to /opt/CPLS/{{ version }}
- name: "Link: Create symlink to extracted version"
  ansible.builtin.file:
    src: "/opt/{{ app_prefix }}/{{ app_version }}"
    dest: "/opt/CPLS/live"
    state: link
    force: yes
    follow: false
  become: yes

# 6. Verification: Check the final result
- name: "Verification: Announce directory check"
  ansible.builtin.debug:
    msg: "Verifying contents of /opt/CPLS/live -> pointing to /opt/{{ app_prefix }}/{{ app_version }}"

- name: "Verification: List content of the symbolic link"
  ansible.builtin.command:
    cmd: "ls -ltr /opt/CPLS/live/"
  register: symlink_contents
  become: yes
  # noqa command-instead-of-module

- name: "Verification: Display results"
  ansible.builtin.debug:
    var: symlink_contents.stdout_lines
Enter fullscreen mode Exit fullscreen mode

Top comments (0)