Browse Source

Add nameserver role

samba
Victor LABORIE 3 years ago
parent
commit
0c5cc59bc6
2 changed files with 40 additions and 0 deletions
  1. +13
    -0
      nameserver/README.md
  2. +27
    -0
      nameserver/tasks/main.yml

+ 13
- 0
nameserver/README.md View File

@ -0,0 +1,13 @@
# nameserver
Set nameserver in /etc/resolv.conf.
## Tasks
Everything is in the `tasks/main.yml` file.
## Available variables
Main variables are :
* `nameservers` : list of IP addresses of DNS servers ;

+ 27
- 0
nameserver/tasks/main.yml View File

@ -0,0 +1,27 @@
---
- name: Get actual nameserver
shell: grep nameserver /etc/resolv.conf | awk '{ print $2 }'
register: grep_nameserver
check_mode: no
changed_when: false
tags:
- nameserver
- name: Set nameserver
lineinfile:
dest: /etc/resolv.conf
line: "nameserver {{ item }}"
state: present
with_items: "{{ nameservers }}"
tags:
- nameserver
- name: Unset others nameserver
lineinfile:
dest: /etc/resolv.conf
line: "nameserver {{ item }}"
state: absent
with_items: "{{ grep_nameserver.stdout_lines }}"
when: item not in nameservers
tags:
- nameserver

Loading…
Cancel
Save