Files
quick_test/versionlock2.yml
2025-07-08 10:50:08 -04:00

58 lines
1.7 KiB
YAML

---
- name: Version Lock
hosts: temp
become: false
gather_facts: false
vars:
lock_pkgs:
- leapp*
- python2-leapp
tasks:
- name: Check for existing excludes in /etc/yum.conf
ansible.builtin.command:
cmd: "grep -i exclude= /etc/yum.conf"
register: yum_exclude_check
failed_when: yum_exclude_check['rc'] not in [0, 1]
changed_when: false
- name: Capture current excludes if present
ansible.builtin.set_fact:
yum_current_excludes: "{{ yum_exclude_check['stdout'] | regex_replace('^exclude=', '') }}"
- name: Debug yum_current_excludes
ansible.builtin.debug:
var: yum_current_excludes
- name: Update yum.conf if Leapp excludes are needed
ansible.builtin.lineinfile:
path: /etc/yum.conf
regexp: "^exclude="
line: "exclude={{ lock_pkgs | join(' ') }} {{ yum_current_excludes }}"
when:
- lock_pkgs | join(' ') not in yum_current_excludes
- name: Re-check for existing excludes
ansible.builtin.command:
cmd: "grep -i exclude= /etc/yum.conf"
register: yum_exclude_recheck
failed_when: yum_exclude_recheck['rc'] not in [0, 1]
changed_when: false
- name: Capture current excludes if present
ansible.builtin.set_fact:
yum_post_excludes: "{{ yum_exclude_recheck['stdout'] | regex_replace('^exclude=', '') }}"
- name: Debug yum_current_excludes
ansible.builtin.debug:
var: yum_post_excludes
- name: Set fact
ansible.builtin.set_fact:
foo_bar: "{{ lock_pkgs | join(' ') }}"
- name: Debug yum_current_excludes minus lock_pkgs
ansible.builtin.debug:
msg: "{{ yum_post_excludes | regex_replace(foo_bar) }} -> {{ foo_bar }}"