From 3c8db06b4f454074f3bb92b31acb0457ad3ebe10 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Thu, 5 Jun 2025 13:11:54 +0200 Subject: [PATCH] Additional custom /etc/hosts entries. --- defaults/main.yml | 1 + tasks/etchosts-customizations.yml | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/defaults/main.yml b/defaults/main.yml index 3b296b4..b322cfd 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -19,6 +19,7 @@ sysctl_custom_file: /etc/sysctl.d/90-custom-values.conf sysctl_opts_reload: yes sysctl_custom_file_state: present custom_etc_hosts_entries: "" +custom_etc_hosts_entries_adjunct: "" # Only name and value are mandatory. The others have defaults sysctl_custom_options: [] diff --git a/tasks/etchosts-customizations.yml b/tasks/etchosts-customizations.yml index a487a7d..a5cc30d 100644 --- a/tasks/etchosts-customizations.yml +++ b/tasks/etchosts-customizations.yml @@ -26,3 +26,32 @@ marker: "# {mark} hosts entries managed by ansible" block: "{{ custom_etc_hosts_entries }}" state: absent + +- name: etchosts-customizations | Additional custom entries to /etc/hosts + when: custom_etc_hosts_entries_adjunct | length > 0 + tags: + - etchosts + block: + - name: etchosts-customizations | Additional custom entries to /etc/hosts + ansible.builtin.blockinfile: + path: /etc/hosts + marker_begin: 'ansible_etchosts_adjunct_start' + marker_end: 'ansible_etchosts_adjunct_end' + marker: "# {mark} additional hosts entries managed by ansible" + block: "{{ custom_etc_hosts_entries_adjunct }}" + state: present + +- name: etchosts-customizations | Remove entries from /etc/hosts + when: custom_etc_hosts_entries_adjunct | length == 0 + tags: + - etchosts + block: + - name: etchosts-customizations | Remove the additional custom entries from /etc/hosts + ansible.builtin.blockinfile: + path: /etc/hosts + marker_begin: 'ansible_etchosts_adjunct_start' + marker_end: 'ansible_etchosts_adjunct_end' + marker: "# {mark} additional hosts entries managed by ansible" + block: "{{ custom_etc_hosts_entries_adjunct }}" + state: absent +