2025-08-21 03:48:22 +02:00
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
# This file adds config blocks to files that are dependent on a single package
|
|
|
|
# being present. If for example the 'git' package is present we want content in
|
|
|
|
# Git's global '/etc/gitconfig' file. If the package is absent that file content
|
|
|
|
# is removed. If after that the file is empty (i.e. has a size of 0 bytes) the
|
|
|
|
# file is deleted.
|
|
|
|
|
|
|
|
- name: 'Add per-package config'
|
|
|
|
when: 'pkg.name in ansible_facts.packages'
|
|
|
|
loop_control:
|
|
|
|
loop_var: 'pkg'
|
|
|
|
label: 'If ''{{ pkg.name }}'' package is present set system-wide config in ''{{ pkg.global_config_file }}'''
|
|
|
|
loop: '{{ package_config }}'
|
|
|
|
ansible.builtin.blockinfile:
|
|
|
|
marker: '# {mark} ANSIBLE MANAGED BLOCK - {{ pkg.name }} {{ pkg.marker }}'
|
|
|
|
path: '{{ pkg.global_config_file }}'
|
|
|
|
append_newline: true
|
|
|
|
prepend_newline: true
|
|
|
|
state: 'present'
|
|
|
|
create: true
|
|
|
|
block: '{{ pkg.global_config }}'
|
|
|
|
|
|
|
|
- name: 'Get stats of global config files'
|
|
|
|
register: 'role_common_packages__global_config_file_stats'
|
|
|
|
loop_control:
|
|
|
|
loop_var: 'pkg'
|
|
|
|
label: 'Get stats of ''{{ pkg.name }}'' system-wide config file ''{{ pkg.global_config_file }}'''
|
|
|
|
loop: '{{ package_config }}'
|
|
|
|
ansible.builtin.stat:
|
|
|
|
path: '{{ pkg.global_config_file }}'
|
|
|
|
|
|
|
|
- name: 'Remove per-package config'
|
2025-08-21 04:08:31 +02:00
|
|
|
when: 'stat_result.pkg.name not in ansible_facts.packages and stat_result.stat.exists'
|
2025-08-21 03:48:22 +02:00
|
|
|
loop_control:
|
|
|
|
loop_var: 'stat_result'
|
|
|
|
label: 'If ''{{ stat_result.pkg.name }}'' package is absent and system-wide config file ''{{ stat_result.pkg.global_config_file }}'' is present remove config file'
|
|
|
|
loop: '{{ role_common_packages__global_config_file_stats.results }}'
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: '{{ stat_result.pkg.global_config_file }}'
|
|
|
|
state: 'absent'
|