Created
March 31, 2018 06:32
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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