Skip to content

Instantly share code, notes, and snippets.

@chuckersjp
Last active May 13, 2020 21:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuckersjp/5474b45de4a2e6c0a05cebfe19a69696 to your computer and use it in GitHub Desktop.
Save chuckersjp/5474b45de4a2e6c0a05cebfe19a69696 to your computer and use it in GitHub Desktop.
Create dnsmasq cluster.conf based on OpenShift inventory hostfile
---
- name: Configure dnsmasq
hosts: all
tasks:
- name: Install dnsmasq
yum:
name: dnsmasq
state: latest
- name: Start and enable dnsmasq
service:
name: dnsmasq
state: started
enabled: yes
- name: Create cluster.conf file
lineinfile:
line: "{{ item }}"
state: present
path: /tmp/cluster.conf
create: yes
with_items:
- "host-record={{ ansible_nodename }},{{ ansible_default_ipv4.address }}"
delegate_to: 127.0.0.1
- name: Add console info to cluster.conf
lineinfile:
line: "{{ item }}"
state: present
path: /tmp/cluster.conf
with_items:
- "host-record={{ openshift_master_cluster_hostname }},{{ lookup('dig', '{{ openshift_master_cluster_hostname }}.') }}"
- "host-record={{ openshift_master_cluster_public_hostname }},{{ lookup('dig', '{{ openshift_master_cluster_public_hostname }}.') }}"
when: openshift_master_cluster_public_host is defined and openshift_master_cluster_hostname is defined
delegate_to: 127.0.0.1
- name: Copy created cluster.conf file
copy:
src: /tmp/cluster.conf
dest: /etc/dnsmasq.d/cluster.conf
notify: restart dnsmasq
handlers:
- name: restart dnsmasq
service:
name: dnsmasq
state: restarted
@chuckersjp
Copy link
Author

This is an ansible playbook to create a dnsmasq cluster.conf file based on all of the nodes found in an OpenShift inventory host file.

@chuckersjp
Copy link
Author

Removed a task that copied a file that was assumed to not exist and added a 'when' condition to verify that the console names were defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment