Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abn/07ace62f61149ce61a1f13e23aeec669 to your computer and use it in GitHub Desktop.
Save abn/07ace62f61149ce61a1f13e23aeec669 to your computer and use it in GitHub Desktop.
Ensure default search domain is preserved when converting Azure VM network interface to be managed by NetworkManager
- hosts: all
tasks:
- name: create custom fact directory
file:
path: /etc/ansible/facts.d
state: directory
- name: insert azure fact file
copy:
src: azure_resolv.fact
dest: /etc/ansible/facts.d/azure_resolv.fact
mode: 0755
register: azure_resolv_fact_file
- name: rediscover facts
setup: ~
when: azure_resolv_fact_file.changed
- name: configure default search domain
lineinfile:
dest: "/etc/sysconfig/network-scripts/ifcfg-{{ ansible_default_ipv4['interface'] }}"
regexp: '^DOMAIN='
line: 'DOMAIN={{ ansible_local.azure_resolv.search_domain }}'
state: present
create: yes
register: interface_domain_configuration
- name: reconfigure interface
shell: "ifdown {{ ansible_default_ipv4['interface'] }} && ifup {{ ansible_default_ipv4['interface'] }}"
when: interface_domain_configuration.changed
#!/usr/bin/env bash
# we are assuming the parent domain stays the same
SEARCH=`grep -Eo '[[:alnum:].]+.internal.cloudapp.net' /etc/resolv.conf || :`
cat <<EOF
{
"search_domain": "${SEARCH}"
}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment