Skip to content
This repository has been archived by the owner on Apr 25, 2020. It is now read-only.

Commit

Permalink
Add domain + search to dhclient.conf and transform dns_searchs into list
Browse files Browse the repository at this point in the history
  • Loading branch information
jdauphant committed Apr 4, 2014
1 parent fd77232 commit e5bb358
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
7 changes: 6 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
---
dns_nameservers: ['8.8.8.8', '8.8.4.4']
dns_remove_resolvconf: true
#dns_searchs: ""
dns_domain: "localdomain"
dns_searchs:
- "{{dns_domain}}"
dns_dhclient_rule: "supersede" # can be supersede or prepend

dns_dhclient_file: "/etc/dhcp/dhclient.conf"
dns_forced_in_dhclientconf: "{{ansible_distribution == 'Ubuntu'}}"
12 changes: 8 additions & 4 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@

- name: Ensure dns servers are configured in dhclient.conf
lineinfile: >
regexp="(supersede|prepend) domain-name-servers"
line="{{dns_dhclient_rule}} domain-name-servers {% for nameserver in dns_nameservers %}{{nameserver}}{% if not loop.last %},{% endif %}{% endfor %};"
dest=/etc/dhcp/dhclient.conf
regexp="#?(supersede|prepend) {{item.name}} "
line="{{dns_dhclient_rule}} {{item.name}} {{item.value}};"
dest="{{dns_dhclient_file}}"
state=present
when: ansible_distribution == "Ubuntu"
with_items:
- { name: 'domain-name-servers', value: '{% for nameserver in dns_nameservers %}{{nameserver}}{% if not loop.last %},{% endif %}{% endfor %}' }
- { name: 'domain-name', value: '\"{{dns_domain}}\"' }
- { name: 'domain-search', value: '{% for domainsearch in dns_searchs %}\"{{domainsearch}}\"{% if not loop.last %}, {% endif %}{% endfor %}' }
when: dns_forced_in_dhclientconf and item.value != ""
tags: [configuration,dns]
2 changes: 1 addition & 1 deletion templates/resolv.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ domain {{dns_domain}}
nameserver {{nameserver}}
{% endfor %}
{% if dns_searchs is defined %}
search {{dns_searchs}}
search {% for name in dns_searchs %}{{name}} {% endfor %}
{% endif %}

0 comments on commit e5bb358

Please sign in to comment.