From 9bb40e7798699f642112eb35e418af58ab547f3e Mon Sep 17 00:00:00 2001 From: rubenb Date: Wed, 14 Feb 2024 16:35:51 +0100 Subject: [PATCH] resolv role --- host_vars/test-playbook.yaml | 6 ++++++ roles/config-resolv/tasks/main.yaml | 10 ++++++++++ roles/config-resolv/templates/resolv.j2 | 7 +++++++ roles/config-resolv/vars/main.yaml | 3 +++ 4 files changed, 26 insertions(+) create mode 100644 roles/config-resolv/tasks/main.yaml create mode 100644 roles/config-resolv/templates/resolv.j2 create mode 100644 roles/config-resolv/vars/main.yaml diff --git a/host_vars/test-playbook.yaml b/host_vars/test-playbook.yaml index eb55f9b..ffda72d 100644 --- a/host_vars/test-playbook.yaml +++ b/host_vars/test-playbook.yaml @@ -7,6 +7,12 @@ hosts: name: localhost - ip: 127.0.1.1 name: test-playbook.lab.dc.verdnatura.es test-playbook + +domain_name: verdnatura.es +search_name: verdnatura.es +resolvs: + - ip: 10.0.0.4 + - ip: 10.0.0.5 ################################################################################ ### FAIL2BAN #################################################################### diff --git a/roles/config-resolv/tasks/main.yaml b/roles/config-resolv/tasks/main.yaml new file mode 100644 index 0000000..090cc85 --- /dev/null +++ b/roles/config-resolv/tasks/main.yaml @@ -0,0 +1,10 @@ +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +- name: Replace old /etc/resolv.conf with new /etc/resolv.conf + template: + src: resolv.j2 + dest: "{{ path_resolv }}" + owner: root + group: root + mode: '0644' + backup: true +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/roles/config-resolv/templates/resolv.j2 b/roles/config-resolv/templates/resolv.j2 new file mode 100644 index 0000000..8eb2aee --- /dev/null +++ b/roles/config-resolv/templates/resolv.j2 @@ -0,0 +1,7 @@ +domain {{ domain_name | default('verdnatura.es') }} +search {{ search_name | default('verdnatura.es') }} +{% if resolvs is defined %} +{% for resolv in resolvs %} +nameserver {{resolv.ip}} +{% endfor %} +{% endif %} \ No newline at end of file diff --git a/roles/config-resolv/vars/main.yaml b/roles/config-resolv/vars/main.yaml new file mode 100644 index 0000000..8e4edcf --- /dev/null +++ b/roles/config-resolv/vars/main.yaml @@ -0,0 +1,3 @@ +--- +# vars file +path_resolv: /etc/resolv.conf \ No newline at end of file