Manage customizations of /etc/hosts.

This commit is contained in:
Andrea Dell'Amico 2024-09-25 18:07:37 +02:00
parent 8a9e104b99
commit a2a6f6ae2a
Signed by: adellam
GPG Key ID: 147ABE6CEB9E20FF
3 changed files with 31 additions and 0 deletions

View File

@ -18,6 +18,7 @@ grub_cmdline_additional_parameters: ""
sysctl_custom_file: /etc/sysctl.d/90-custom-values.conf sysctl_custom_file: /etc/sysctl.d/90-custom-values.conf
sysctl_opts_reload: yes sysctl_opts_reload: yes
sysctl_custom_file_state: present sysctl_custom_file_state: present
custom_etc_hosts_entries: ""
# Only name and value are mandatory. The others have defaults # Only name and value are mandatory. The others have defaults
sysctl_custom_options: [] sysctl_custom_options: []

View File

@ -0,0 +1,28 @@
---
- name: etchosts-customizations | Add entries to /etc/hosts
when: custom_etc_hosts_entries | length > 0
tags:
- etchosts
block:
- name: etchosts-customizations | Add custom entries to /etc/hosts
ansible.builtin.blockinfile:
path: /etc/hosts
marker_begin: 'ansible_etchosts_customizations_start'
marker_end: 'ansible_etchosts_customizations_end'
marker: "# {mark} Customization to bashrc installed via ansible"
block: "{{ custom_etc_hosts_entries }}"
state: present
- name: etchosts-customizations | Remove entries from /etc/hosts
when: custom_etc_hosts_entries | length == 0
tags:
- etchosts
block:
- name: etchosts-customizations | Remove custom entries from /etc/hosts
ansible.builtin.blockinfile:
path: /etc/hosts
marker_begin: 'ansible_etchosts_customizations_start'
marker_end: 'ansible_etchosts_customizations_end'
marker: "# {mark} Customization to bashrc installed via ansible"
block: "{{ custom_etc_hosts_entries }}"
state: absent

View File

@ -7,6 +7,8 @@
ansible.builtin.import_tasks: locale.yml ansible.builtin.import_tasks: locale.yml
- name: Set the timezone - name: Set the timezone
ansible.builtin.import_tasks: timezone.yml ansible.builtin.import_tasks: timezone.yml
- name: Manage customizations to the /etc/hosts file
ansible.builtin.import_tasks: etchosts-customizations.yml
- name: Sysctl kernel parameters - name: Sysctl kernel parameters
ansible.builtin.import_tasks: sysctl.yml ansible.builtin.import_tasks: sysctl.yml
- name: Grub command line parameters - name: Grub command line parameters