Skip to content

Instantly share code, notes, and snippets.

@glennswest
Created April 8, 2017 06:26
Show Gist options
  • Save glennswest/164d167df4fdb1d46c6f32be321bdedf to your computer and use it in GitHub Desktop.
Save glennswest/164d167df4fdb1d46c6f32be321bdedf to your computer and use it in GitHub Desktop.
Change RHEL 7 to use dnsmaq and /etc/host to do forward and reverse lookup
---
- hosts: all:bastion
vars:
description: "Update /etc/hosts"
tasks:
- name: setup
setup:
- name: "Change PEERDNS=yes to PEERDNS=no"
replace:
dest: /etc/sysconfig/network-scripts/ifcfg-eth0
regexp: '^PEERDNS=yes$'
replace: 'PEERDNS=no'
- name: "Fix ifcfg DNS Entry"
lineinfile:
dest: /etc/sysconfig/network-scripts/ifcfg-eth0
line: 'DNS1=127.0.0.1'
state: present
- name: 'Copy and Backup the resolv.conf'
copy:
src: /etc/resolv.conf
dest: /etc/dnsmasq-resolv.conf
backup: yes
- name: 'dnsmasq to use new resolver'
replace:
dest: /etc/dnsmasq.conf
regexp: '^#resolv-file=$'
replace: 'resolv-file=/etc/dnsmasq-resolv.conf'
backup: yes
- name: 'restart dnsmasq'
service:
name: dnsmasq
state: restarted
- name: 'Remove resolv.conf'
file:
state: absent
path: /etc/resolv.conf
- name: 'Update resolv.conf'
blockinfile:
dest: /etc/resolv.conf
create: yes
block: |
nameserver 127.0.0.1
search .
- name: 'restart network'
service:
name: network
state: restarted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment