Files
role-common-packages/tasks/base-package-auxiliary-settings-single-package-single-config.yml

42 lines
1.7 KiB
YAML
Raw Normal View History

# 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'
when: 'stat_result.pkg.name not in ansible_facts.packages'
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'